【发布时间】:2012-10-21 09:30:44
【问题描述】:
我在 windows 中使用 curl exe 来与我的 Django 后端通信。
以下是正在使用的命令。
curl --dump-header - -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data "{\"uid\":12,\"token\":\"asdert\"}" http://localhost:8000/restapi/v1/foo/
现在这会以错误的格式提供数据。即在视图中,帖子显示了这些数据 打印请求.POST
{"{\"uid\":12,\"access_token\":\"asdert\"}": [""]}
发布json数据的正确方法是什么?
编辑:
我尝试了其他几种方法,例如 我正在尝试使用 http://slumber.in/ 与我的 rest api 进行通信。
即使在这里得到与上面相同的结果。
import slumber
api = slumber.API("http://localhost/restapi/v1/"
api.foo.post({"uid":"100"})
视图摘录 打印请求.POST
{u'{"uid": "100"}': [u'']}
附: - curl --dump-header - -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data "uid=12&token=asdert" http://localhost:8000/restapi/v1/foo/
这行得通。但这不是 Json 格式。
【问题讨论】:
-
否,如果您在视图中打印 request.POST,它会给出一个字典,其中键为上述数据,并且为空值。