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

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

问题描述

我的问题:

运行Windows 7并使用可执行命令行工具卷曲我的localhost服务器api的POST数据返回我一个似乎很常见的错误。

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. curl -i -X POST -H'Content-Type:application / json'-d'{data1:data here ,data2:data2 goes here}'http:localhost / path / to / 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吗?这样看起来像一个完全破碎的shell
,不能正确处理单引号和双引号。
我刚刚试过这个命令行,它的工作正常在我的Linux盒子。
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 goes here \,\data2\:\data2 goes 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 here here \ \\data2 \:\data2 here 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笔记本电脑,并能够使用curl版本标记为 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.

这篇关于cURL POST命令行在WINDOWS RESTful服务上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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