To post JSON data using curl, you can use the curl
command with the -X POST
option to specify the HTTP method and the -H "Content-Type: application/json"
option to set the content type to JSON. You can then pass the data you want to post as a JSON string using the -d
option.
Here is an example of how to post JSON data using curl:
curl -X POST -H "Content-Type: application/json" -d '{"key1":"value1", "key2":"value2"}' http://example.com/api
This will send a POST request to the http://example.com/api
URL with a JSON body containing the data {"key1":"value1", "key2":"value2"}
.
You can also pass a file containing the JSON data using the @
symbol followed by the filename. For example:
curl -X POST -H "Content-Type: application/json" -d @data.json http://example.com/api
This will send a POST request to the http://example.com/api
URL with the contents of the data.json
file as the request body.
Note that you will need to replace http://example.com/api
with the actual URL of the API endpoint you want to send the request to.