Saurabh Chaturvedi
Saurabh Chaturvedi

Reputation: 2166

curl request does not accept a password containing "@" for a url with HTTP basic authentication

As we know that a curl request for a url that is protected by basic authentication can be made by using a format like this curl -v http://username: [email protected] . But i have observed that passing credentials like this only works if password does not have a "@" itself. For example If my request is curl -v http://user01:[email protected] it will work . But if it is curl -v http://user01:hello@[email protected] , it fails . How can we make the first @ to be understood as a password, as currently i think @ is taken as a conventional delimiter before passing credentials, and therefore request gets confused as to what is the password . Any thoughts on this, or am i missing anything ?

Upvotes: 0

Views: 1565

Answers (1)

Yuri Schimke
Yuri Schimke

Reputation: 13488

Use -u which defaults to basic auth

   -u, --user <user:password>
          Specify the user name and password to use for server authentication. Overrides -n, --netrc and  --netrc-
          optional.

          If you simply specify the user name, curl will prompt for a password.

          The user name and passwords are split up on the first colon, which makes it impossible to use a colon in
          the user name with this option. The password can, still.

Possibly even better would be to define your passwords in the netrc file and then avoid passwords on the command line altogether.

Upvotes: 1

Related Questions