How to post JSON with the curl command

Run the following command:


curl -H "Content-Type: application/json" -X POST -d 'JSONTOPOST' http://URLOFTHESERVER

The curl command can be used to POST json from a command line to a url.

Example:

When using the curl command:

  • -H parameter is used to pass a header to the request; here it is the content-type application/json.
  • -X is used for the method, here POST.
  • -D is used for the payload, here the input value.
The output will be the json reponse of the url encoded value of "This is a test"


$ curl -H "Content-Type: application/json" -X POST -d '{"input":"This is a test"}' http://oliviertech.com/rest/urlencode/
{"output":"This+is+a+test","input":"This is a test"}

References:

Curl

Share this article:

Recent Comments