Calling curl command on Windows

I'm trying to run a command curl

from the command line on Windows, but for the life of me, I can't figure out how I should avoid it.

I am doing 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 get 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? Or am I completely ignoring the real problem?

+3


source to share


3 answers


The error XDMP-DOCROOTTEXT

indicates that the server is trying to parse the payload as XML

it does not work.

The header Content-Type

tells the server what you are sending XML

, but the payload JSON

.



Try changing the title Content-Type

toapplication/json

+2


source


This works on Windows:



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

      

+4


source


The quote is hell. "With the Windows command and your prompt, I assume you mean cmd.com?" This gives a quote just like Linux shells.

For this simplified experiment, I recommend switching to 2 kinds of quotes to avoid escaping. But even then it is unlikely to work

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 with a Unix-like shell like running cygwin ( http://www.cygwin.com/ ) or perhaps xmlsh (www.xmlsh.org) that run like Linux.

You will really have the nightmare of launching anything complicated through the Windows command line natively.

-David

0


source







All Articles