How to do HTTP-request/call with JSON payload from command-line?

Use curl, assuming the data is POST'ed, something like

curl -X POST http://example.com/some/path -d '{"version": "1.1", "method":"progr","id":2,"params":{"call":...} }'

If you're just retrieving the data with a GET , and don't need to send anything bar URL parameters, you'd just run curl http://example.com/some/path


curl --request POST \
--url http://localhost:8099/someservice/services/boo \
--header 'authorization: Basic dkfhsdlepwmdseA==' \
--header 'cache-control: no-cache' \
--header 'content-type: application/json' \
--data '{"value": "24.127.1212.123"}'

You could use wget with post-file as well, which I found useful.

wget --post-file=[file] --header=Content-Type:application/json [URL]

You can keep the content in the file and the content will be sent as post data.


You could use wget as well:

wget -O- --post-data='{"some data to post..."}' \
  --header='Content-Type:application/json' \
  'http://www.example.com:9000/json'

Calling wget with the option -O providing the - (space in between will be ignored, so it could also be written as -O -) to it as its value will cause wget to output the HTTP response directly to standard output instead into a file. The long option name for that is --output-document=file.