zoukankan      html  css  js  c++  java
  • file_get_contents无法请求https连接的解决方法

    PHP.ini默认配置下,用file_get_contents读取https的链接,就会如下错误:

    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前面的;删掉,重启服务就可以了。

    1、打开PHP目录,在php.ini中把“extension=php_openssl.dll”前面的“;”去掉 
    2、复制php安装目录中的: libeay32.dll、ssleay32.dll至c:windowssystem32 
    3、复制php_openssl.dll至c:windowssystem32 
    4、重启IIS或者apache环境 
    这样就可以打开php的openssl_open支持,继续安装了
    

     
    2.linux下的PHP,就必须安装openssl模块,安装好了以后就可以访问了。
    3.如果服务器你不能修改配置的话,那么就使用curl函数来替代file_get_contents函数

     /**-- curl for https --**/
     function curl_for_https($url){
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL,$url);
    	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    	//不加下面的 返回的就是 access_token=F5A4FEDE95AD3D88DD29EC1F904B24C8&expires_in=7776000&refresh_token=2BF2DD1B05CF510CD2EEE2466009EFC0bool(true)
            //并且页面直接输出后 就不向下执行了
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    	$result = curl_exec($ch);
    	curl_close($ch);
    	return $result;
     }    
    
  • 相关阅读:
    Gengxin讲STL系列——Set
    理解Python的With语句
    Python中Non-ASCII character 'xe7' in file的问题解决
    gnome-terminal的一些调整
    硬盘的CHS寻址
    Wiz发布cnblog笔记
    cygwin安装man手册
    linux命令行使用
    小步前进
    学习的感觉真好
  • 原文地址:https://www.cnblogs.com/mr-amazing/p/3770820.html
Copyright © 2011-2022 走看看