简体   繁体   English

卷曲与POST不起作用,request.POST为空

[英]curl with POST not working, request.POST is empty

I'm attempting to send a post request with some json data using: 我正在尝试使用以下方式发送带有一些json数据的发布请求:

curl --verbose -X POST -d @testfile.json http://oururl.com/someapi --header "Content-Type:application/json"

the view on the other end reads request.POST.dict() -- but request.POST is showing up empty (though content length is getting set)! 另一端的视图读取request.POST.dict() ,但是request.POST显示为空(尽管设置了内容长度)! I've used this method before and never had this happen, can't figure out what is going wrong. 我以前使用过这种方法,从未发生过这种情况,无法弄清楚出了什么问题。

You're posting JSON. 您正在发布JSON。 request.POST is for form-encoded data. request.POST用于表单编码的数据。

You should be accessing request.body and passing it through json.loads() . 您应该访问request.body并将其传递给json.loads()

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

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