对于具有HTTP基本身份验证的URL,curl请求不接受包含“@”的密码

时间:2016-08-17 17:53:29

标签: linux http curl basic-authentication

我们知道,通过使用像curl -v http://username:password@xyz.com这样的格式,可以对受基本身份验证保护的URL进行curl请求。但我观察到,只有密码本身没有“@”才能传递这样的凭证。例如,如果我的请求是curl -v http://user01:helloworld@xyz.com,它将起作用。但如果它是curl -v http://user01:hello@world@xyz.com,它就会失败。我们怎样才能将第一个@理解为密码,因为目前我认为@在传递凭证之前被视为传统的分隔符,因此请求会对密码是什么感到困惑。对此有任何想法,或者我错过了什么?

1 个答案:

答案 0 :(得分:1)

使用-u默认为基本身份验证

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

可能更好的方法是在netrc文件中定义密码,然后完全避免命令行上的密码。