11

I have the following cURL request:

curl -H 'Host: example.com' -H 'Accept-encoding: gzip, deflate' -H 'Accept: /' -H 'User-Agent: iPhone' -H 'Secret-Key: 04d798d5ed2e560fb596bcfc3838fec0' -H 'Date: 2017-04-23T00:57:00.05+0200' -H 'Content-type: application/json' --data-binary '{"RegDate": "2017-04-23", "Username": "JamesRicky", "Password": "0001"}' 'example.com/user'

It works perfectly on Linux, but on Windows (using Command Prompt / Powershell), it gives me the following response:

curl: (6) Couldn't resolve host 'example.com''
curl: (6) Couldn't resolve host 'gzip,'
curl: (6) Couldn't resolve host 'deflate''
curl: (6) Couldn't resolve host '*'
curl: (6) Couldn't resolve host 'iPhone''
curl: (6) Couldn't resolve host '04d798d5ed2e560fb596bcfc3838fec0''
curl: (6) Couldn't resolve host '2017-04-23T00:57'

This is because of how Command Prompt handles Double / Single quotes. I have been trying for the past 30 minutes to try to figure out how I would format it on Windows.

I tried the following things:

1.

curl -H "Host: example.com" -H "Accept-encoding: gzip, deflate" -H "Accept: /" -H "User-Agent: iPhone" -H "Secret-Key: 04d798d5ed2e560fb596bcfc3838fec0" -H "Date: 2017-04-23T00:57:00.05+0200" -H "Content-type: application/json" --data-binary ^"{^"RegDate^": ^"2017-04-23^", ^"Username^": ^"JamesRicky^", ^"Password^": "^0001^"}^" ^"example.com/user^"

2.

curl -H "Host: example.com" -H "Accept-encoding: gzip, deflate" -H "Accept: /" -H "User-Agent: iPhone" -H "Secret-Key: 04d798d5ed2e560fb596bcfc3838fec0" -H "Date: 2017-04-23T00:57:00.05+0200" -H "Content-type: application/json" --data-binary \"{\"RegDate\": \"2017-04-23\", \"Username\": \"JamesRicky\", \"Password\": "\0001\"}\" \"example.com/user\"

None of the above works...

Any ideas how to format the first cURL request so it will work on Windows?

JamesRicky
  • 201
  • 1
  • 3
  • 17
  • I didn't try this with curl on Windows, but generally three(!!!) consecutive double-quotes are treated as a single double-quote (but part of the string). I.e. `curl ... --data-binary "{"""RegDate""": """2017... 0001"""}" ...`. More info here: https://stackoverflow.com/a/15262019/1482455 – YePhIcK Oct 31 '17 at 19:19

2 Answers2

7

Inside the single or double qouted element, escape additional single or double quotes with a backslash.

Per https://stackoverflow.com/a/15828662/147637

This works great on curl on win 10 command line.

Jonesome Reinstate Monica
  • 6,618
  • 11
  • 65
  • 112
1

See this thread. The quick answer is that you may need to use the unicode-encoded double-quote (\u0022) or single-quote (\u0027).

https://stackoverflow.com/a/18612754/279782

roryhewitt
  • 4,097
  • 3
  • 27
  • 33