4

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.

2 Answers 2

6

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.

2

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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