所以我有这个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被淹没了 – 空间不工作!
如果我想要留言的话,我将如何发送这条消息?
使用双引号“,并在网址中使用%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
你只需要引用你的JSON作为字符串文字:
curl --insecure -g -X POST -H "Content-Type: application/json" -d "{\"from\":\"someName\",\"message\":\"this is a message\"}" https://some/website/here
另外,使用-V获取更多关于正在发生的事情的信息(它抛出了这个错误“接近`}'”的解析错误)。