PHP使用file_get_contents函数抓取 https 网站网页内容时出错,可采用以下两种方法:

方法一:

打开php.ini找到 ;extension=php_openssl.dll ,去掉双引号”;” ,重启web服务器即可。

方法二:

<?php
//file_get_contents抓取https地址内容
function getCurl($url){
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 $result = curl_exec($ch);
 curl_close ($ch);
 return $result;?>

Post Comment

Your email address will not be published. Required fields are marked *