4

当我将原始字符串作为 JSON REST 服务调用的输入发布时,它正在执行前:

curl -d "{\"input1\": \"as\", \"input2\": \"ad\"}"  -i -X POST -H "Content-Type:application/json"  http://localhost/rtygies/Service1.svc/rest/receivedata1 

但是,当我将 xml 作为输入发布时,会出现如下错误:

curl -d "{\"input1\": \"<xml></xml>\", \"input2\": \"<xml></xml>\"}"  -i -X POST -H "Content-Type:application/json"  http://localhost/rtygies/Service1.svc/rest/receivedata1 

错误:<此时出乎意料

我在 Windows 中使用 curl。

任何人都可以说如何从 curl 以 JSON 格式将 xml 作为字符串输入发布到 Rest 服务

4

3 回答 3

12

实际上,我不知道是什么情况,但是< is unexpected this time 当我尝试以下命令(在 Windows 上)时出现错误消息:

curl -u admin:password -XPOST -H 'Content-type: text/xml' -d '<namespace><prefix>newWorkspace</prefix><uri>http://geoserver.org</uri></namespace>' http://localhost:8080/geoserver/rest/namespaces

然后我将单引号更改为双引号,它起作用了。

于 2013-12-15T23:25:22.230 回答
2

我对双引号没有运气,但是用 ^ 转义 < 和 > 对我有用。

所以你的卷曲变成..

curl -d "{\"input1\": \"^<xml^>^</xml^>\", \"input2\": \"^<xml^>^</xml^>\"}"  -i -X POST -H "Content-Type:application/json"  http://localhost/rtygies/Service1.svc/rest/receivedata1
于 2020-10-08T10:20:42.717 回答
2

重定向符号可以通过 "

尝试使用

curl -d "{\"input1\": \""<xml></xml>"\", \"input2\": \""<xml></xml>"\"}"  -i -X POST -H "Content-Type:application/json"  http://localhost/rtygies/Service1.svc/rest/receivedata1
于 2017-05-16T15:20:59.290 回答