$cSession = curl_init();
curl_setopt($cSession,CURLOPT_URL,"http://hai:hai@[email protected]/users/current.json");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
$userDetail = curl_exec($cSession);
密码中'@'后面的字符作为URL。
不要将您的凭据放在URL字符串中。像这样设置它们:
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");
您应urlencode()
用户名和密码。那应该可以解决问题。
urlencode()
然后您可以在URL中传递$user = 'hai';
$pass = 'hai@7';
$creds = urlencode($user) . ':' . urlencode($pass)
// result hai:hai%407
字符串,或作为$creds
。