【问题标题】:curl with POST not working, request.POST is emptycurl 与 POST 不工作,request.POST 为空
【发布时间】:2014-05-19 21:18:23
【问题描述】:

我正在尝试使用以下方式发送带有一些 json 数据的发布请求:

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

另一端的视图显示request.POST.dict() -- 但request.POST 显示为空(尽管内容长度已设置)!我以前用过这种方法,从来没有出现过这种情况,不知道是怎么回事。

【问题讨论】:

    标签: python json django curl


    【解决方案1】:

    您正在发布 JSON。 request.POST 用于表单编码数据。

    您应该访问request.body 并将其传递给json.loads()

    【讨论】:

    • 我试着看中它。对于其他有此问题的人,您仍然可以使用上述方法,只需删除 --header (默认为表单数据编码)并将文件结构更改为 things=[{"id":5,"column":"foo"}] &lang=en_US &user_country=US
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 2020-10-05
    相关资源
    最近更新 更多