成都网站建设设计

将想法与焦点和您一起共享

如何解决file_get_contents无法请求https连接的问题-创新互联

这篇文章主要介绍“如何解决file_get_contents无法请求https连接的问题”,在日常操作中,相信很多人在如何解决file_get_contents无法请求https连接的问题问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何解决file_get_contents无法请求https连接的问题”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

成都创新互联是一家专注于网站建设、成都做网站与策划设计,宁蒗网站建设哪家好?成都创新互联做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:宁蒗等地区。宁蒗做网站价格咨询:18982081108

错误: Warning: fopen() [function.fopen]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?

解决方案有3:

1.windows下的PHP,只需要到php.ini中把extension=php_openssl.dll前面的;删掉,重启服务就可以了。

2.linux下的PHP,就必须安装openssl模块,安装好了以后就可以访问了。

3.如果服务器你不能修改配置的话,那么就使用curl函数来替代file_get_contents函数,当然不是简单的替换啊。还有相应的参数配置才能正常使用curl函数。

对curl函数封装如下:

复制代码 代码如下:

function http_request($url,$timeout=30,$header=array()){  
        if (!function_exists('curl_init')) {  
            throw new Exception('server not install curl');  
        }  
        $ch = curl_init();  
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
        curl_setopt($ch, CURLOPT_HEADER, true);  
        curl_setopt($ch, CURLOPT_URL, $url);  
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);  
        if (!emptyempty($header)) {  
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);  
        }  
        $data = curl_exec($ch);  
        list($header, $data) = explode("\r\n\r\n", $data);  
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);  
        if ($http_code == 301 || $http_code == 302) {  
            $matches = array();  
            preg_match('/Location:(.*?)\n/', $header, $matches);  
            $url = trim(array_pop($matches));  
            curl_setopt($ch, CURLOPT_URL, $url);  
            curl_setopt($ch, CURLOPT_HEADER, false);  
            $data = curl_exec($ch);  
        }  
        if ($data == false) {  
            curl_close($ch);  
        }  
        @curl_close($ch);  
        return $data;  
}

到此,关于“如何解决file_get_contents无法请求https连接的问题”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


分享题目:如何解决file_get_contents无法请求https连接的问题-创新互联
URL分享:http://chengdu.cdxwcx.cn/article/dhgipp.html