【发布时间】:2011-12-07 11:33:31
【问题描述】:
当我尝试在我的网站中读取一些 HTTPS 网址时遇到问题。
如果我使用“http”,则没有问题(使用 file_get_contents 和 curl),但是当我将“http”替换为“https”时,这些方法不起作用。
我收到一些错误:
failed to open stream: operation failed occured
Failed to enable crypto occured
SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
在我的浏览器中,所有方法都有效: https://ssl10.ovh.net/~fyprbqhq/_perso/facebook.myclimb/test.php(显示屏应显示“OK”)
在 phpinfo() 中我得到了:
openssl
OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.8c 05 Sep 2006
如果你有任何想法。
感谢您的帮助。
(Ps:在我的情况下,get_headers() 不适用于 https)
更多信息:
file_get_contents:
$data = file_get_contents("https://ssl10.ovh.net/~fyprbqhq/_perso/facebook.myclimb/test.php");
卷曲:
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "http://ssl10.ovh.net/~fyprbqhq/_perso/facebook.myclimb/test.php");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($curl_handle);
curl_close($curl_handle);
【问题讨论】:
-
您确定 file_get_contents 可以通过 http 运行吗?我对 fopen/curl 有两个不同的想法,但只有当 file_get_contents 在这两种情况下都失败时它们才是正确的:) 还有.. 你尝试过另一个 https url 吗?
-
你可以把你用来下载文件内容的那一行放上去。
-
根据我在其他论坛上阅读的内容,是的 file_get_contents 应该可以工作。但在这些情况下(https),我读到 curl 更合适。尽管如此,我试图阅读一个谷歌 https 链接,它的工作原理(两种方法)。