kumarjt
December 14, 2017, 1:21pm
1
Hi.
I 'm trying to hit a REST api and retrieve a JSON feed, and the URL has special characters in it.
Something like:
Example Domain
The below curl command is failing
curl -X GET https://www.example.com/?sample=name&id=1001
saying bad command at id=1001
I am going to use this as part of my script which will accept the url as parameter.
Can i use any option of the curl command to encode the & characters in the url automatically?
Please help.
Thank you.
Kumarjit
RudiC
December 14, 2017, 1:26pm
2
Try escaping the &
character to prevent the shell from sending the curl
command to background.
For sheer curiosity - which special character do you see?
Instead of looking for characters that are special to the shell and individually escaping them, it might be simpler to just quote the argument you're passing to curl
:
curl -X GET "https://www.example.com/?sample=name&id=1001"
kumarjt
December 19, 2017, 10:21am
4
Thanks all. The command worked with enclosing the URL with double quotes and it worked.
Regards
Kumarjit