Question Detail
I have been trying for a few days to figure out how to convert a cURL command that works perfectly in the Linux terminal but just can’t figure out how to format it correctly so that I can use it in a windows bat file. Any help would be highly appreciated.
The Linux cURL command that works perfectly in Linux:
curl -X PUT \
-H 'Accept:application/json; charset=utf-8' \
-H 'Content-type:application/json; charset=utf-8' \
http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/pushpublish/mapentries/ppsource \
-d'
{
"serverName": "_defaultServer_",
"sourceStreamName": "newStream",
"entryName": "ppsource",
"profile": "rtmp",
"host": "localhost",
"application": "testlive",
"userName": "testUser",
"password": "pass",
"streamName": "myStream"
}'
How can I do the same in windows cmd?
Question Answer
- Change single quotes to double quotes
- Change the line continuation character from
\
to ^
- Check the effective command with
echo on
Or use a browser (using windows), open the developer mode (F12) and copy a network entry with copy as windows curl
If a line contains only a single or an odd number of quotes, the last quote has to be escaped, that ensures the caret at the line end still works.
Ex.
echo on
curl -X PUT ^
-H 'Accept:application/json; charset=utf-8' ^
-H 'Content-type:application/json; charset=utf-8' ^
http://localhost:8087/v2/^
-d^"^
{^
"serverName": "_defaultServer_",^
Okay, so I managed to figure it out with the suggestions from others on here and a few other websites.
curl -X PUT ^
-H "Accept:application/json; charset=utf-8" ^
-H "Content-type:application/json; charset=utf-8" ^
"http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/pushpublish/mapentries/ppsource" -d "{^
\"serverName\": \"_defaultServer_\",^
\"sourceStreamName\": \"newStream\",^
\"entryName\": \"ppsource\",^
\"profile\": \"rtmp\",^
\"host\": \"localhost\",^
\"application\": \"testlive\",^
\"userName\": \"\",^
\"password\": \"\",^
\"streamName\": \"myStream\"^
}"
Use carret ^
as a line continuation symbol instead of backslash \
, and doublequote all string instead of singlequoute. Include line termination to json at the end.