5

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.

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? Or am I overlooking the real issue entirely?

BlairHippo
  • 9,502
  • 10
  • 54
  • 78

3 Answers3

9

This works in Windows:

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

The XDMP-DOCROOTTEXT error indicates the server is trying to parse the payload as XML and failing.

The Content-Type header is telling the server that you're sending XML, but the payload is JSON.

Try changing the Content-Type header to application/json

John Dvorak
  • 26,799
  • 13
  • 69
  • 83
ehennum
  • 7,295
  • 13
  • 9
0

Quoting is hell. By "Windows Command Line and your prompt I presume you mean cmd.com ?. That doest quote the same as linux shells.

For this simplistic experiment I recommend going for 2 kinds of quotes to avoid escaping But even then its 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 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.

You really are going to have a nightmare running anything complex through the windows command line natively.

-David

DALDEI
  • 3,722
  • 13
  • 9
  • Thanks, David. I'm running cmd.exe. The outer-double inner-single approach didn't work. I'm trying to avoid doing this with Cygwin and keep this simple if possible, but I'm running out of patience. The really irritating part is I know full well I figured out how to do this once, but I can't recall HOW.... – BlairHippo Feb 19 '13 at 22:00
  • Maybe try things mentioned here Maybe try http://stackoverflow.com/questions/2835039/graphical-http-client-for-windows – Eric Bloch Feb 19 '13 at 23:37