当用户名或密码包含“ @”字符时如何使用cURL登录?

问题描述 投票:1回答:2
$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。

php php-curl
2个回答
0
投票

不要将您的凭据放在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");

0
投票

您应urlencode()用户名和密码。那应该可以解决问题。

urlencode()

然后您可以在URL中传递$user = 'hai'; $pass = 'hai@7'; $creds = urlencode($user) . ':' . urlencode($pass) // result hai:hai%407 字符串,或作为$creds

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.