-1

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?

3 Answers 3

4
  • 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_",^
Sign up to request clarification or add additional context in comments.

2 Comments

@user2956477 @jeb thanks for the reply. I replaced the \ with ^ and ' with ". When i run the bat file, it considers the first word of each new line after -d" as a command and so shows the following error '{' is not recognized as an internal or external command, operable program or batch file.
@user3191135 You should add your attempt in your question. Use echo on in your batch file to see how the lines are interpreted. Probably you try -d"^ this fails, because the caret doesn't work there, the quote escapes all characters up to the end of the line
2

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\"^
}"

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.