109 Views
Sure, here’s a quick guide to posting JSON data using cURL:
- Set the Content-Type Header: Start by setting the Content-Type header to
application/json
to indicate that you’re sending JSON data.
-H "Content-Type: application/json"
- Specify the Request Method: If you’re sending a POST request, use the
-X
option to specify the method as POST.
-X POST
- Provide JSON Data: Use the
-d
option followed by the JSON data enclosed in single quotes.
-d '{"key1":"value1", "key2":"value2"}'
- Send the Request to the API Endpoint: Finally, specify the URL of the API endpoint where you want to send the JSON data.
http://example.com/api/endpoint
Putting it all together, a complete cURL command for posting JSON data would look like this:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"key1":"value1", "key2":"value2"}' \
http://example.com/api/endpoint
Replace http://example.com/api/endpoint
with the actual URL of the API endpoint you want to send the JSON data to, and adjust the JSON data as needed.