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