通过curl进行身份验证并获取资源

时间:2017-11-02 09:42:00

标签: php authentication curl

https://test.e-mac.com/PublishingImages/News/ibtikar%20app.png

此图片受密码保护,您需要输入用户名和密码才能访问此图片。但是我怎么能通过卷曲来实现它。我使用下面的PHP代码并得到401错误。在Web浏览器中,它以相同的用户名和密码打开

$url = 'https://test.e-mac.com/PublishingImages/News/ibtikar%20app.png';

$username = 'example_user_name';
$password = '********';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

var_dump($output);

0 个答案:

没有答案
相关问题