Having trouble escaping quotes and braces

CurlEscapingCommand PromptQuotesCurly Braces

Curl Problem Overview


I am trying to execute the following line in Command Prompt:

curl -X POST -d '{ "method" : "account_info", "params" : [ { "account" : "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"} ] }' http://s1.ripple.com:51234

However, I get the following:

curl: (6) Could not resolve host: method
curl: (7) Failed connect to :80; No error
curl: (6) Could not resolve host: account_info,
curl: (6) Could not resolve host: params
curl: (7) Failed connect to :80; No error
curl: (3) [globbing] illegal character in range specification at pos 2
curl: (3) [globbing] unmatched brace at pos 2
curl: (6) Could not resolve host: account
curl: (7) Failed connect to :80; No error
curl: (3) [globbing] unmatched close brace/bracket at pos 35
curl: (3) [globbing] unmatched close brace/bracket at pos 1
curl: (3) [globbing] unmatched close brace/bracket at pos 1
unable to parse request

I am on Windows, and the error has to do with quotes, braces, and globbing. I tried escaping quotes by preceding them with a backslash, with no luck.

Curl Solutions


Solution 1 - Curl

Do not use single quotes. Escape any double quotes within the string with a \.

curl -X POST -d "{ \"method\" : \"account_info\", \"params\" : [ { \"account\" : \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\"} ] }" http://s1.ripple.com:51234

Window's command.exe doesn't seem to support single quotes. PowerShell does, but there are still some problems when using them, so the best solution is to not use them at all.

Solution 2 - Curl

You can use curl -g to turn off globbing:

curl -g -X POST -d '{ "method" : "account_info", "params" : [ { "account" : "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"} ] }' http://s1.ripple.com:51234

Easier than escaping all those brackets.

Solution 3 - Curl

Try the basic one to post something.

curl -X POST --data '{"username":"username", "password":"password"}' --header "Content-Type:application/json" http://127.0.0.1:8000/your_url/

Solution 4 - Curl

For windows users: you can download git bash for running the below curl command.

curl http://localhost:8080/subpage --include --header "Content-Type: application/json" --request "POST" --data '{"variable": "value"}

Solution 5 - Curl

In the above responses, it is important to note that data are specified in JSON format, which should require to specify --header as Alok's answer.

It is also possible to define it in "url" format like this:

curl -X POST --data "method=account_info&params=[…]" http://s1.ripple.com:51234

and avoid specifying --header "Content-Type…"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkillajouleView Question on Stackoverflow
Solution 1 - CurlManuel GörlichView Answer on Stackoverflow
Solution 2 - CurlcanduView Answer on Stackoverflow
Solution 3 - CurlAlok ChoudharyView Answer on Stackoverflow
Solution 4 - CurlSHIVA BANDARIView Answer on Stackoverflow
Solution 5 - Curlbcag2View Answer on Stackoverflow