在Windows中转义curl命令

时间:2013-02-19 20:42:26

标签: windows curl marklogic

我正在尝试从Windows命令行运行curl命令,但对于我的生活,我无法弄清楚我应该如何逃避它。

我正在执行此操作:

C:\WINDOWS\system32>curl --anyauth --user user:password -X POST -d "{\"rest-api\":{\"name\":\"BizSimDebug3\"}}" -H "Content-type: application/xml" http://localhost:8002/v1/rest-apis

我得到了这个:

<rapi:error xmlns:rapi="http://marklogic.com/rest-api">
  <rapi:status-code>400</rapi:status-code>
  <rapi:status>Bad Request</rapi:status>
  <rapi:message-code>RESTAPI-INVALIDCONTENT</rapi:message-code>
  <rapi:message>Your bootstrap payload caused the server to throw an error.  Underlying error message: XDMP-DOCROOTTEXT: xdmp:get-request-body() -- Invalid root text "{&amp;quot;rest-api&amp;quot;:{&amp;quot;name&amp;quot;:&amp;quot;BizSimDebug3&amp;quot;}}" at  line 1</rapi:message>
</rapi:error>

我还需要做些什么来逃避-d标志中的内部引号吗?或者我完全忽略了真正的问题?

3 个答案:

答案 0 :(得分:7)

这适用于Windows:

 
curl -i -X POST -H "Content-Type: application/json" -d "{\"Field1\": 123, \"Field2\": 456 }" "http://localhost:8080"
 

答案 1 :(得分:2)

XDMP-DOCROOTTEXT错误表示服务器正在尝试将有效负载解析为XML并失败。

Content-Type标头告诉服务器您正在发送XML,但有效负载为JSON

尝试将Content-Type标题更改为application/json

答案 2 :(得分:0)

引用是地狱。通过“Windows命令行和你的提示我认为你的意思是cmd.com?。那引用与linux shell相同。

对于这个简单的实验,我建议使用2种引号以避免转义但即使这样它也不太可能工作

curl --anyauth --user user:password -X POST -d "{'rest-api':{'name':'BizSimDebug3'}}" -H "Content-type: application/xml" http://localhost:8002/v1/rest-apis

使用像unix一样的shell,比如运行cygwin(http://www.cygwin.com/)或者xmlsh(www.xmlsh.org)就像linux一样逃脱,可能会有更好的运气。

你真的要通过windows命令行本地运行任何复杂的噩梦。

-David