php - 如何验证https站点的用户名/密码以访问php中的文件

标签 php xml authentication https openssl

我想从 https://test24.highrisehq.com/tasks/upcoming.xml 访问一个 xml 文件使用 PHP。 以下是示例代码:

$xml = simplexml_load_file("https://test24.highrisehq.com/tasks/upcoming.xml");

由于连接是安全的,我收到一个错误:

Warning: simplexml_load_file(https://test24.highrisehq.com/tasks/upcoming.xml) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in D:\wamp\www\xml\index.php on line 3

在访问文件之前,我需要在代码中的某处输入用户名和密码。谁能告诉他我怎样才能做到这一点?

问候 乌梅尔

最佳答案

cURL,你求cURL ! (说真的,cURL 很棒。向下滚动该链接,您会在下面找到 HTTP 身份验证示例)

// HTTP authentication 
$url = "https://www.example.com/protected/"; 
$ch = curl_init();     
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //see link below  
$result = curl_exec($ch);  
curl_close($ch);  
echo $result; 

您可以找到有关使用 CURLOPT_SSL_VERIFYPEER 的信息 here .

关于php - 如何验证https站点的用户名/密码以访问php中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6604892/

相关文章:

PHP 从 MySQL 获取下一个结果

android - 使用 XmlResourceParser 解析内部存储中的 xml 文件

java - 删除 xsi :type after marshalling abstract class with hierarchy

javascript - 为什么我的 XSLTProcessor transformToDocument 不起作用?

asp.net - 基于 Referrer、cookie 或其他内容限制对网站的访问

php - 什么是 Php gettext 扩展的最简单的 Php 替代品,它可以被所有类型的免费托管支持

php - phpmailer 的问题

php - Python/Django 中是否有相当于 PHP 的 hash_hmac?

android - 需要更新服务版本?

python - 如何使用OpenCV对IP摄像机进行身份验证