file_get_contents 访问 ssl 错误的两种解决方法

第一种,也是最常见的,参考:https://jingyan.baidu.com/article/72ee561a54af56e16038df60.html

打开php.ini文件,extension=php_openssl.dll去掉前面的分号,allow_url_include = off改为allow_url_include = On,然后重启服务就可以了。如图

 

第二种,在国内比较少见,我也是偶然的机会在国外网站发现了,参考:https://stackoverflow.com/questions/26148701/file-get-contents-ssl-operation-failed-with-code-1-and-more
 
文中代码是这样的:
<?php
$arrContextOptions=array(
    "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);  

$response = file_get_contents("https://maps.co.weber.ut.us/arcgis/rest/services/SDE_composite_locator/GeocodeServer/findAddressCandidates?Street=&SingleLine=3042+N+1050+W&outFields=*&outSR=102100&searchExtent=&f=json", false, stream_context_create($arrContextOptions));

echo $response; ?>

关键代码就是这行: "ssl"=>array

 
我电脑使用的是phpStudy,win7系统,两种方法结合使用,在本地测试通过,网页没有假死。
 
posted @ 2018-07-01 18:19  stma  阅读(635)  评论(0编辑  收藏  举报