I want to post the following JSON:
{
"cities": {
"chicago": 123,
"boston": 245
}
}
Using curl
as x-www-form-urlencoded
without using a .json file. I cannot figure out how to build the curl -F ...
To post form data with Curl, you can use one of two command-line parameters: -F (--form) or -d (--data). The -F command-line parameter sends form data with the multipart/form-data content type, and the -d command-line parameter sends form data with the application/x-www-form-urlencoded content type.
To post JSON data using Curl, you need to set the Content-Type of your request to application/json and pass the JSON data with the -d command line parameter. The JSON content type is set using the -H "Content-Type: application/json" command line parameter. JSON data is passed as a string.
You can pass the body of the POST message to Curl with the -d or --data command-line option. Curl will send data to the server in the same format as the browser when submitting an HTML form. To send binary data in the body of a POST message with Curl, use the --data-binary command-line option.
For application/x-www-form-urlencoded
you could try:
curl -d "param1=value1¶m2=value2" -X POST http://localhost:3000/blahblah
Where param1=value...
have to be your JSON data as chicago=123&boston=245
Or explicit form:
curl -d "param1=value1¶m2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:3000/blahblah
Instead of http://localhost:3000/blahblah
you should provide real URL of your service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With