42

How do I include special characters like @ and & in the cURL POST data? I'm trying to pass a name and password like:

curl -d name=john passwd=@31&3*J https://www.mysite.com

This would cause problems as @ is used for loading files and & for specifying more than one key/value. Is there some way I can escape these characters? \@ and \& don't seem to work.

1

Just found another solutions worked for me. You can use '\' sign before your one special.

passwd=\@31\&3*J
3

Try this:

export CURLNAME="john:@31&3*J"
curl -d -u "${CURLNAME}" https://www.example.com
  • 1
    Does not work if the exclamation point ("!") is one of the special characters. – Thane Plummer Oct 7 '16 at 2:49
13

Double quote (" ") the entire URL .It works.

curl "http://www.mysite.com?name=john&passwd=@31&3*J"
  • 3
    The request is supposed to be a POST, not a GET. – Yngvar Kristiansen Mar 5 '15 at 13:39
0

I did this

~]$ export A=g

~]$ export B=!

~]$ export C=nger


   curl http://<>USERNAME<>1:$A$B$C@<>URL<>/<>PATH<>/
48

cURL > 7.18.0 has an option --data-urlencode which solves this problem. Using this, I can simply send a POST request as

curl -d name=john --data-urlencode passwd=@31&3*J https://www.mysite.com
  • Will this work for headers too ? – Bilal Fazlani Apr 21 '17 at 15:59
  • I have 7.52.1 and I can't get this to work... I can do --data-urlencode "something=it's a test" but not with double quotes or @ symbols... – PJ Brunet Jan 20 at 4:09
  • Remember to use --data-urlencode only for the data part that needs it. For example, the following will not work when you combine the data into one entity: curl --data-urlencode "name=john&passwd=@31&3*J" https://www.example.com – Mr-IDE Apr 27 at 10:08
32

How about using the entity codes...

@ = %40

& = %26

So, you would have:

curl -d 'name=john&passwd=%4031%263*J' https://www.mysite.com

  • Could you please be kind enough to specify entity code for "+" – Kasun Siyambalapitiya May 1 at 12:08
  • did you figure out the '+' part for this? – shreyas K N Sep 20 at 6:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.