【问题标题】:Escaping curl command in Windows在 Windows 中转义 curl 命令
【发布时间】:2013-02-04 16:40:52
【问题描述】:

我正在尝试从 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 标志中的内引号吗?还是我完全忽略了真正的问题?

【问题讨论】:

    标签: windows curl marklogic


    【解决方案1】:

    这适用于 Windows:

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

      • headdesk 赞。我怀疑我可能在做一些愚蠢的事情。这确实是问题所在。谢谢!
      【解决方案3】:

      引用是地狱。通过“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 命令行本地运行任何复杂的东西。

      -大卫

      【讨论】:

      • 谢谢,大卫。我正在运行 cmd.exe。外双内单方法不起作用。我试图避免使用 Cygwin 执行此操作,并尽可能保持简单,但我已经没有耐心了。真正令人恼火的部分是我很清楚我曾经想过如何做到这一点,但我不记得如何......
      • 也许试试这里提到的东西也许试试stackoverflow.com/questions/2835039/…
      猜你喜欢
      • 2012-11-03
      • 2012-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      • 2015-03-07
      相关资源
      最近更新 更多