Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl in windows - how do i put a space in the json?

Tags:

json

curl

windows

so i have this curl request (running on a windows cmd prompt):

curl --insecure -g -X POST -H "Content-Type: application/json" -d {\"from\":\"someName\",\"message\":\"this is a message\"} https://some/website/here

When i run this, i get an error:

curl: (6) Could not resolve host: is; Host not found
curl: (6) Could not resolve host: a; Host not found
curl: (6) Could not resolve host: message; Host not found

Which seems to be because the json is munged up - the spaces are not working!

How would i send this message, if i wanted spaces to be in the, uh, message?

like image 686
bharal Avatar asked Sep 04 '25 17:09

bharal


2 Answers

Use double quotes " and use %20 in url

Just tried on my windows command prompt now. You were missing escape on the DATA part

Your code

curl --insecure -g -X POST -H "Content-Type: application/json" -d {\"from\":\"someName\",\"message\":\"this is a message\"} https://some/website/here

should be escaped like this

curl --insecure -g -X POST -H "Content-Type: application/json" -d "{\"from\":\"someName\",\"message\":\"this is a message\"}" https://some/website/here
like image 165
fedmich Avatar answered Sep 07 '25 08:09

fedmich


You just need to quote your JSON as a string literal:

curl --insecure -g -X POST -H "Content-Type: application/json" -d "{\"from\":\"someName\",\"message\":\"this is a message\"}" https://some/website/here

also, use the -V for more info on what is happening (it threw this error "parse error near `}'").

like image 37
pherris Avatar answered Sep 07 '25 07:09

pherris