Use „curl“ and „wget“ with an Ampersand-URL!
07/04/2018 (9688x read)
Two easy ways to use the tools „curl“ and „wget“ with an URL that has an ampersand („&“) in it: That is important to send more then one parameter with the URL to a skript on a webserver. On a website you can send multiple parameters as a GET-Request via the URL: The first URL-parameter is divided with a questionmark „?“ from the file-name, all other parameters are divided with the ampersand „&“:
website.php?parameter1=1¶meter2=2¶meter3=3
This works perfectly when entered in the URL bar of a browser, but when using the Linux shell an ampersand character „&“ has a different meaning. To be able to access a website or a script on a server with an ampersand character in the URL, there are two possibilities: The first solution is to put the complete URL inside of single or double quotation marks:
curl 'http://192.168.1.1/website.php?parameter1=1¶meter2=2'
wget 'http://192.168.1.1/website.php?parameter1=1¶meter2=2'
Another alternative, if you cannot use quotation marks, would be to escape the ampersand character with a backslash before it: „\&“ This way it is possible to use the ampersand inside the URL without the need of quotation marks:
curl http://192.168.1.1/website.php?parameter1=1\¶meter2=2
wget http://192.168.1.1/website.php?parameter1=1\¶meter2=2