Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 721
BlairHippo Avatar asked Feb 19 '13 20:02

BlairHippo


People also ask

How do you escape curl command?

The backslash ( \ ) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.

Can we run curl command in Windows?

Invoke curl.exe from a command window (in Windows, click Start > Run and then enter "cmd" in the Run dialog box). You can enter curl --help to see a list of cURL commands.

What is equivalent of curl in Windows?

The most popular Curl equivalents for Windows are: Wget. Wget is a free command-line tool for downloading files using the HTTP, HTTPS, and FTP protocols. Wget is a non-interactive command-line tool that can be easily invoked from scripts, deferred commands, non-X-Windows terminals, etc. VSCode Rest Client.


1 Answers

This works in Windows:

 
curl -i -X POST -H "Content-Type: application/json" -d "{\"Field1\": 123, \"Field2\": 456 }" "http://localhost:8080"
 
like image 126
michaelp Avatar answered Oct 06 '22 07:10

michaelp