post JSON data from Curl

Really very useful tip.
To post JSON format data in CURL from termial, you need to specify header parameter
-H "Content-Type: application/json".
Springmvc would reject this request body if JSON header not specified.

1
2
3
curl -H "Content-Type: application/json" \
-d '{"username":"xyz","password":"xyz"}' \
http://localhost:8080/api/login

Also note that, you could use -X GET option to indicate using GET method at the meantime of using -d option, which might originally treat as a way of POST data.
Actually -d option just indicate the data within it need to be treat as request body.


post JSON data from Curl
https://rug.al/2014/2014-04-10-post-json-data-from-curl/
Author
Rugal Bernstein
Posted on
April 10, 2014
Licensed under