【发布时间】:2012-08-03 18:37:02
【问题描述】:
我的问题: 使用命令行工具卷曲我的本地主机服务器,同时发送一些数据以及我的 POST 请求不起作用。
似乎是什么导致了错误: 想象一下这样的事情
curl -i -X POST -H 'Content-Type: application/json' -d '{"data1": "data goes here", "data2": "data2 goes here"}' http:localhost/path/to/api
返回数据的结果
curl: (6) Could not resolve host: application; No data record of requested type
curl: (6) Could not resolve host: data goes here,; No data record of requested type
curl: (6) Could not resolve host: data2; No data record of requested type
curl: (3) [globbing] unmatched close brace/bracket at pos 16
经过一番搜索,我发现问题不是用于请求的 sintax,因为它适用于 UNIX shell。
您可能使用 Windows 吗?看起来像一个完全破碎的外壳 不能正确处理单引号和双引号。 我刚刚尝试了该命令行,它在我的 linux 机器上运行良好。 http://curl.haxx.se/mail/archive-2011-03/0066.html
我试图解决那些“逃避它”的问题,但它仍然没有用
2.
curl -i -X POST -H 'Content-Type: application/json' -d '{\"data1\": \"data在这里\", \"data2\": \"data2在这里\ "}' http://localhost/path/to/api
3.
curl -i -X POST -H 'Content-Type: application/json' -d '{\"data1\": \"data在这里\", \"data2\": \"data2在这里\ "}' http://localhost/path/to/api
所以我放弃了。 Windows 似乎弄乱了在 POST 上发送的 JSON 对象
【问题讨论】:
-
请不要在您的问题标题中添加
[solved]。如果您已经找到问题的答案,您应该将其作为答案发布。 -
感谢@CodyGray 的警告。我会更正我的帖子。
-
如果您的机器上安装了 git,您可以使用 git bash 进行 curl。它可以省去很多麻烦。
标签: windows api post curl command-line