Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL send JSON as x-www-form-urlencoded [closed]

Tags:

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 ...

like image 322
Kousha Avatar asked Sep 13 '18 19:09

Kousha


People also ask

How do you pass X www form Urlencoded parameters in Curl?

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.

How do I post JSON with Curl?

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.

How do you pass BODY IN POST request Curl?

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.


1 Answers

For application/x-www-form-urlencoded you could try:

curl -d "param1=value1&param2=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&param2=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.

like image 98
ikos23 Avatar answered Oct 09 '22 21:10

ikos23