[英]How to login with with cURL when username or password include the “@” character?
$cSession = curl_init();
curl_setopt($cSession,CURLOPT_URL,"http://hai:hai@7@redmine.org/users/current.json");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
$userDetail = curl_exec($cSession);
The character after the '@' in the password is taken as the URL.密码中'@'后的字符作为URL。
Don't put your credentials in the URL string.不要将您的凭据放在 URL 字符串中。 Set them like this:
像这样设置它们:
curl_setopt($cSession, CURLOPT_URL,"http://redmine.org/user/current.json");
curl_setopt($cSession, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($cSession, CURLOPT_USERPWD, "$username:$password");
You should urlencode()
the username and password.您应该
urlencode()
用户名和密码。 That should solve the problem.那应该可以解决问题。
$user = 'hai';
$pass = 'hai@7';
$creds = urlencode($user) . ':' . urlencode($pass)
// result hai:hai%407
Then you can pass that $creds
string in the URL, or as CURLOPW_USERPWD
.然后你可以在 URL 中传递
$creds
字符串,或者作为CURLOPW_USERPWD
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.