简体   繁体   English

在Windows中转义curl命令

[英]Escaping curl command in Windows

I'm trying to run a curl command from the command line in Windows, but for the life of me I can't figure out how I'm supposed to escape it. 我正试图在Windows中从命令行运行curl命令,但对于我的生活,我无法弄清楚我应该如何逃避它。

I'm executing this: 我正在执行这个:

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

And I'm getting this: 我得到了这个:

<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>

Is there something else I need to do to escape the inner quotes in the -d flag? 还有什么我需要做的事情来逃避-d标志中的内部引号吗? Or am I overlooking the real issue entirely? 还是我完全忽略了真正的问题?

这适用于Windows:


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

The XDMP-DOCROOTTEXT error indicates the server is trying to parse the payload as XML and failing. XDMP-DOCROOTTEXT错误表示服务器正在尝试将有效负载解析为XML并失败。

The Content-Type header is telling the server that you're sending XML , but the payload is JSON . Content-Type标头告诉服务器您正在发送XML ,但有效负载是JSON

Try changing the Content-Type header to application/json 尝试将Content-Type标头更改为application/json

Quoting is hell. 引用是地狱。 By "Windows Command Line and your prompt I presume you mean cmd.com ?. That doest quote the same as linux shells. 通过“Windows命令行和你的提示我认为你的意思是cmd.com?。那引用与linux shell相同的引用。

For this simplistic experiment I recommend going for 2 kinds of quotes to avoid escaping But even then its unlikely to work 对于这个简单的实验,我建议使用2种引号以避免转义但即使这样也不太可能

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

Better luck might be had by going with a unix-like shell such as running cygwin ( http://www.cygwin.com/ ) or maybe xmlsh (www.xmlsh.org) which escape like linux does. 通过运行像cygwin( http://www.cygwin.com/ )或者xmlsh(www.xmlsh.org)这样的类似unix的shell可以获得更好的运气。

You really are going to have a nightmare running anything complex through the windows command line natively. 你真的会在本机上通过windows命令行运行任何复杂的噩梦。

-David -大卫

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

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