vishnumanohar
vishnumanohar

Reputation: 713

How to escape special characters in header of curl command

I want to curl a url through REST call. The call requires a authorization header to be sent along with it. The authorization header contains a !(apostrophe) character in it. when I send it it throws the following error.

-bash: !FeTSs: event not found

curl -H "X-Med-Authorization:3b7N/FNDcEVX&v09n8O6jeUz9l!FeTSs;cSf3wz/mDsvzKGX" -X GET http://192.168.1.2:8383/dcCore/health/

I searched out there are answer to escape special characters in post data but not in headers.

Upvotes: 4

Views: 19057

Answers (2)

Mohnish
Mohnish

Reputation: 2045

You can use $'' form to pass arguments as-is. E.g.

curl -H $'appCookie=x-Abc!123' http://localhost

Ref: wiki.bash-hackers.org and www.gnu.org

Upvotes: 2

Jack Lenox
Jack Lenox

Reputation: 357

I came across this problem myself and got fairly frustrated trying to find a solution until I discovered that backslashing the offending characters is good enough!

So:

curl -H "X-Med-Authorization:3b7N/FNDcEVX&v09n8O6jeUz9l!FeTSs;cSf3wz/mDsvzKGX" -X GET http://192.168.1.2:8383/dcCore/health/

Just needs to become:

curl -H "X-Med-Authorization:3b7N/FNDcEVX&v09n8O6jeUz9l\!FeTSs;cSf3wz/mDsvzKGX" -X GET http://192.168.1.2:8383/dcCore/health/

You can check that the correct header is being sent by viewing the output when cURL is run with the --verbose flag. In that I see:

> X-Med-Authorization:3b7N/FNDcEVX&v09n8O6jeUz9l!FeTSs;cSf3wz/mDsvzKGX

No backslash. Boom. I suspect you've found a solution to this by now but hopefully this helps someone down the line.

Upvotes: 6

Related Questions