在窗口卷曲 - 我如何在json中放置一个空格?

时间:2014-05-28 14:06:23

标签: json windows curl

所以我有这个卷曲请求(在Windows cmd提示符下运行):

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

当我运行时,我收到错误:

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

这似乎是因为json被吹了 - 空间不起作用!

如果我希望空格出现在呃消息中,我将如何发送此消息?

3 个答案:

答案 0 :(得分:7)

使用双引号并在网址中使用%20

现在就试试我的Windows命令提示符。你在DATA部分错过了逃避

您的代码

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

应该像这样转义

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

答案 1 :(得分:3)

您只需要将JSON引用为字符串文字:

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

另外,使用-V获取有关正在发生的事情的更多信息(它抛出此错误“解析错误在}}附近”。)

答案 2 :(得分:0)

试试这个(而不是 -d ),例如:

--data-raw "{"blah":"带空格的字符串"}"