cURL command runs in Linux but not Windows 2008

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?

Ian M

Posted 2018-02-02T11:23:50.563

Reputation: 151

The problem is more likely the windows command prompt interpreting the single and double quotes differently, not anything to do with curl – hardillb – 2018-02-02T11:26:01.840

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 – 2018-02-02T11:26:41.783

Answers

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

hardillb

Posted 2018-02-02T11:23:50.563

Reputation: 390

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).

mvw

Posted 2018-02-02T11:23:50.563

Reputation: 721