cURL send JSON as x-www-form-urlencoded
Solution 1
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.
Solution 2
The whole point of curl -F, according to the man page, is "to POST data using the Content-Type multipart/form-data according to RFC 2388." In other words, it's best used when you need to emulate an HTML form with a file input.
Instead use curl -d to specify the raw POST data:
curl -d '{"cities":{"chicago":123,"boston":245}}' https://example.com
If this is actually how they expect data, it is a misconfigured server, as x-www-form-urlencoded data should be in the form key=value.
Related videos on Youtube
Kousha
Biomedical Engineering Master student at UBC. I develop apps for both fun and large scale application for clients.
Updated on July 28, 2022Comments
-
Kousha 4 monthsI want to post the following JSON:
{ "cities": { "chicago": 123, "boston": 245 } }Using
curlasx-www-form-urlencodedwithout using a .json file. I cannot figure out how to build thecurl -F ...-
anubhava about 4 yearscurl -F 'data={"cities":{"chicago":123,"boston":245}}' ... -
chepner about 4 yearsWhat name/value pairs does the remote end expect? There's no one input that particular JSON maps to.
-