繁体   English   中英

在Windows中转义curl命令

[英]Escaping curl command in Windows

我正试图在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 -i -X POST -H "Content-Type: application/json" -d "{\"Field1\": 123, \"Field2\": 456 }" "http://localhost:8080"

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

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

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

引用是地狱。 通过“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

通过运行像cygwin( http://www.cygwin.com/ )或者xmlsh(www.xmlsh.org)这样的类似unix的shell可以获得更好的运气。

你真的会在本机上通过windows命令行运行任何复杂的噩梦。

-大卫

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM