3

I have installed cURL on Windows 2008 Server, and am trying to execute the command below. This command executes fine on an Ubuntu machine on the same LAN, but when I run it in Windows I get these errors:

curl -H "Content-Type: application/json" -X POST -d '{ "entity_id": "switch.study_cam" }' https://192.168.1.99:8123/api/services/switch/turn_off?api_password=MyAPIPassword --insecure
curl: (6) Could not resolve host: entity_id
curl: (6) Could not resolve host: switch.study_cam
curl: (3) [globbing] unmatched close brace/bracket in column 1
{"message": "Data should be valid JSON"}

I've tested cURL on Windows with http://www.google.com and it returned valid HTML, so it seems to have installed correctly.

Are there syntax differences between cURL for Windows and Linux, or is there some other explanation for why the command above fails in Windows?

  • The problem is more likely the windows command prompt interpreting the single and double quotes differently, not anything to do with curl – hardillb Feb 2 '18 at 11:26
  • The problem is most likely differences in the shell you use, because e.g. cmd.exe and bash support different syntax. Looking at the error, it starts where ', { and " comes into play. You surely need some escaping or such using ^ or so. – Thorsten Schöning Feb 2 '18 at 11:26
2

The problem is more likely the windows command prompt interpreting the single and double quotes differently, not anything to do with curl.

Try reversing the double and single quotes in the JSON section:

curl -H "Content-Type: application/json" -X POST -d "{ 'entity_id': 'switch.study_cam' }" https://192.168.1.99:8123/api/services/switch/turn_off?api_password=MyAPIPassword --insecure
| improve this answer | |
1

I would put the JSON into a file, e.g. json.txt, and use curl -d @json.txt to avoid the quote handling issue by the shell.

This would give something like

curl -H "Content-Type: application/json" -X POST -d @json.txt \
https://192.168.1.99:8123/api/services/switch\
/turn_off?api_password=MyAPIPassword --insecure

If you miss a Unix shell, MSYS2 is a nice system to add the usual gang of tools to your Windows machine (it must be newer than Windows XP / Windows Server 2003 though).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.