如何使用curl在基本的http auth上发布JSON数据?

时间:2012-06-09 18:56:04

标签: api rest curl

我想使用curl unix命令发布数据我通过googling得到的内容如下所示:

curl --dump-header - -H "Content-Type: application/json"  -X POST --data '{"description": "This will prbbly be my lst post.", "transaction_id": "2011-05-22T00:46:38", "account": "another-post"}' http://127.0.0.1:8000/api/transaction/

但是它会在下面的响应头后面返回:

curl: (6) Could not resolve host: POST; nodename nor servname provided, or not known
HTTP/1.0 401 UNAUTHORIZED
Date: Sat, 09 Jun 2012 18:50:37 GMT
Server: WSGIServer/0.1 Python/2.7.1
Content-Type: text/html; charset=utf-8

我做错了什么

1 个答案:

答案 0 :(得分:4)

您不需要编写“POST”来发布curl(1)帖子 - 如果您给它--data参数,它会自动执行此操作。

相反,它错误地将“POST”视为您要发送到的URL,并且正如您所想象的那样失败。放弃这个词你应该很好。

相关问题