Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special characters like @ and & in cURL POST data

Tags:

post

curl

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.

like image 384
Bernhard Heijstek Avatar asked Apr 08 '12 03:04

Bernhard Heijstek


People also ask

What symbols are special characters?

A special character is one that is not considered a number or letter. Symbols, accent marks, and punctuation marks are considered special characters. Similarly, ASCII control characters and formatting characters like paragraph marks are also special characters.

What is the special character & used for?

What is an &? & is called an ampersand symbol (pronounced “AM- per-sand”). Essentially, it means “and”. It is used both (a) in the body of the paper as part of a citation and (b) at the end of the paper as part of a reference.


2 Answers

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.example.com 

Summarizing the comments, in case of mixed "good" and "bad" data and exclamation marks inside we can use on Windows:

curl -d "grant_type=client_credentials&client_id=super-client&acr_values=tenant:TNT123" --data-urlencode "client_secret=XxYyZ21D8E&%fhB6kq^mXQDovSZ%Q*!ipINme"  https://login.example.com/connect/token 
like image 121
Bernhard Heijstek Avatar answered Sep 21 '22 09:09

Bernhard Heijstek


How about using the entity codes...

@ = %40

& = %26

So, you would have:

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

like image 38
Biagio Arobba Avatar answered Sep 19 '22 09:09

Biagio Arobba