43

Having a problem with CURL and the HTTP User and password Auth methods, it is not liking the exclamation mark, I've tried escaping the following ways:

Tried and failed...

/usr/bin/curl -u 'UserName\WithSlash:PasswordWithExclamation!' https://test.com/
/usr/bin/curl -u UserName\\WithSlash:PasswordWithExclamation\! https://test.com/

Not working for basic or digest if it matters (using --anyauth) ... getting 401 denied...

What am I doing incorrectly?

Kladskull
  • 10,332
  • 20
  • 69
  • 111
  • Out of curiousity, have you tried just using the username and letting curl prompt for the password, or using the `--netrc` opt and putting the username and password in a .netrc file? – kojiro Jul 12 '12 at 03:01
  • .netrc is looking to work so far... – Kladskull Jul 12 '12 at 03:24
  • What version of bash are you using? I have a feeling that I may have seen this behavior under a very old version of bash (can't give you a version number). For another example, see http://stackoverflow.com/questions/3291692/irix-bash-shell-expands-expression-in-single-quotes-yet-shouldnt – Barton Chittenden Jul 12 '12 at 03:45

3 Answers3

50
 curl -u UserName\\WithSlash:PasswordWithExclamation\!  http://....

works fine.

it sends

 GET / HTTP/1.1
 Authorization: Basic VXNlck5hbWVcV2l0aFNsYXNoOlBhc3N3b3JkV2l0aEV4Y2xhbWF0aW9uIQ==
 User-Agent: curl/7.21.0
 Host: teststuff1.com:80
 Accept: */*

which is "UserName\WithSlash:PasswordWithExclamation!" in the auth string.

pizza
  • 7,296
  • 1
  • 25
  • 22
2

not that complicated, just use "". at least it works on Linux.

for example:

curl -u "username:passwdwithspecialchar" GET https://....
Meloman
  • 3,558
  • 3
  • 41
  • 51
Shen Yong
  • 21
  • 2
0

If you know the server supports Basic auth, you could set the header directly:

curl --header "Authorization: Basic $(base64 --wrap=0 credentials)" https://example.org

This way you can store the user and password (UserName\WithSlash:PasswordWithExclamation!) without any escaping in the credentials file you pass to the base64 command.

Martin
  • 2,573
  • 28
  • 22