简体   繁体   中英

How to post JSON data using curl over basic http auth?

I want to post data using curl unix command what I got by googling is doing like below:

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/

But its is returning following response header like below:

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

What I am doing wrong

You don't need to write "POST" to make curl(1) post - it will do that automatically if you give it a --data argument.

Instead, it is mistaking "POST" for the URL you want to send to, and failing as you might imagine. Drop that word and you should be good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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