繁体   English   中英

Django发布请求数据

[英]Django post request data

我试图将数据发布到我的Django服务器但是当我检查服务器时,Querydict是空的。 当我从浏览器调用它看起来确实很好。

import requests
import json
headers =  {
       "AUTHORIZATION": "1234",
       "Content-type": "application/json",
       "Accept": "text/plain"
    }
print headers    

payload = {
    "start_date_s":"04/01/2016",
    "start_date_e":"04/15/2016"
}


r = requests.post('http://localhost:8000/get-ticket-data',headers=headers, json = json.dumps(payload))
print r.content
print r.text

如果你使用json参数,你应该按原样传递你的dict,不要转储它( docs ):

r = requests.post('http://localhost:8000/get-ticket-data',headers=headers, json=payload)

如果你发送json请求,你需要在django视图中使用request.body来获取它,而不是request.POST

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM