在WINDOWS RESTful服务卷曲POST命令行 [英] cURL POST command line on WINDOWS RESTful service

查看:418
本文介绍了在WINDOWS RESTful服务卷曲POST命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:

运行Windows 7和使用可执行命令行工具卷曲的POST数据我的本地服务器API返航我,似乎是非常常见的一个错误。

Running windows 7 and using the executable command line tool to curl my localhost server api for POST data was returning me an error that seems to be really common.

请求正在不同之处在于数据未到达服务器,因为它应该引起我的REST服务与空值插入数据的发送。

The request was being sent properly with the exception that the data was not reaching the server as it should causing my REST service to insert data with null values.

什么似乎导致了错误:
想象这样的事情

What seems to be causing the error: imagine something like this


  1. 卷曲-i -X​​ POST -H内容类型:应用程序/ JSON'-D'{DATA1:数据放在这里,数据2:数据2到这里} HTTP:本地主机/路径/要/ API

  1. 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。

After some searching i figured out that problem couldn't be the sintax used for the request since it works on UNIX shells.

您可能使用Windows?说了这么看起来像一个完全破壳
  不妥善处理单引号VS双引号。
  我刚试过,命令行,它在我的Linux机器上运行良好。
  <一href=\"http://curl.haxx.se/mail/archive-2011-03/0066.html\">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

卷曲-i -X​​ POST -H内容类型:应用程序/ JSON'-D'{\\DATA1 \\:\\的数据放在这里\\,\\数据2 \\:\\数据2到这里\\ }的http://本地主机/路径/要/ 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。

卷曲-i -X​​ POST -H内容类型:应用程序/ JSON'-D'{\\DATA1 \\\\:\\的数据放在这里\\,\\数据2 \\\\:\\数据2变这里\\}的http://本地主机/路径/要/ API

curl -i -X POST -H 'Content-Type: application/json' -d '{\"data1\"\: \"data goes here\", \"data2\"\: \"data2 goes here\"}' http: //localhost/path/to/api

所以我放弃了。
窗户似乎与POST发送的JSON对象搞乱

So i gave up. Windows seems to messing up with the JSON object sent on POST

推荐答案

我跑进我的Win7的X64笔记本电脑相同的问题,并能得到它的工作使用标记<卷曲发行A HREF =HTTP:/ /curl.haxx.se/latest.cgi?curl=win64-ssl-sspi\">Win64 - 使用非常类似的命令行格式通用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\"}"

其中仅不同于利用周围的那些逃脱双引号和头参数值,你的第二逃生的版本。绝对preFER Linux命令语法的更多。

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服务卷曲POST命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆