bharal
bharal

Reputation: 16154

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

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?

Upvotes: 4

Views: 9259

Answers (3)

Fabrizio
Fabrizio

Reputation: 109

try this (instead of -d ), e.g.:

--data-raw "{"blah":"a string with spaces"}"

Upvotes: 0

pherris
pherris

Reputation: 17693

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 `}'").

Upvotes: 4

fedmich
fedmich

Reputation: 5381

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

Upvotes: 9

Related Questions