WINDOWS RESTful 服务上的 cURL POST 命令行 [英] cURL POST command line on WINDOWS RESTful service
问题描述
我的问题:使用命令行工具卷曲我的本地主机服务器,同时发送一些数据和我的 POST 请求不起作用.
My problem: Using the command line tool to curl my localhost server while sending some data along with my POST request is not working.
导致错误的原因:想象一下这样的事情
curl -i -X POST -H 'Content-Type: application/json' -d '{"data1": "data go here", "data2": "data2 go 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
经过一番搜索,我发现问题不是用于请求的语法,因为它适用于 UNIX shell.
After some searching i figured out that problem couldn't be the sintax used for the request since it works on UNIX shells.
您可能使用 Windows 吗?看起来像一个完全破碎的外壳不能正确处理单引号与双引号.我刚刚尝试了该命令行,它在我的 linux 机器上运行良好.http://curl.haxx.se/mail/archive-2011-03/0066.html
Are you possibly using Windows? That so looks like a completely broken shell that doesn't properly deal with single-quotes vs double-quotes. I just tried that command line and it worked fine on my linux box. http://curl.haxx.se/mail/archive-2011-03/0066.html
我试图解决那些逃避它"的问题,但它仍然没有用
I tried to work around with those " escaping it \" but it still didn't work
2.
curl -i -X POST -H 'Content-Type: application/json' -d '{\"data1\": \"data go here\", \"data2\": \"data2 go here\"}' http://localhost/path/to/api
curl -i -X POST -H 'Content-Type: application/json' -d '{\"data1\": \"data goes here\", \"data2\": \"data2 goes here\"}' http: //localhost/path/to/api
3.
curl -i -X POST -H 'Content-Type: application/json' -d '{\"data1\": \"data go here\", \"data2\": \"data2 go here\"}' http://localhost/path/to/api
curl -i -X POST -H 'Content-Type: application/json' -d '{\"data1\": \"data goes here\", \"data2\": \"data2 goes here\"}' http: //localhost/path/to/api
所以我放弃了.Windows 似乎搞乱了 POST 上发送的 JSON 对象
So i gave up. Windows seems to messing up with the JSON object sent on POST
推荐答案
我在我的 win7 x64 笔记本电脑上遇到了同样的问题,并且能够使用标有 Win64 - Generic w SSL 使用非常相似的命令行格式:
I ran into the same issue on my win7 x64 laptop and was able to get it working using the curl release that is labeled Win64 - Generic w SSL by using the very similar command line format:
C:\Projects\curl-7.23.1-win64-ssl-sspi>curl -H "Content-Type: application/json" -X POST http://localhost/someapi -d "{\"Name\":\"Test Value\"}"
这与您的第二个转义版本的区别仅在于在转义和标头参数值周围使用双引号.绝对更喜欢 linux shell 语法.
Which only differs from your 2nd escape version by using double-quotes around the escaped ones and the header parameter value. Definitely prefer the linux shell syntax more.
这篇关于WINDOWS RESTful 服务上的 cURL POST 命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!