当前位置:网站首页>file_get_contents 访问 ssl 错误的两种解决方法

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

2022-04-23 05:57:00 自己收藏学习

转自博客园https://www.cnblogs.com/devcjq/articles/9250800.html

第一种,也是最常见的,参考: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

 

文中代码是这样的:

1

2

3

4

5

6

7

8

9

10

11

<?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系统,两种方法结合使用,在本地测试通过,网页没有假死。

 

版权声明
本文为[自己收藏学习]所创,转载请带上原文链接,感谢
https://blog.csdn.net/pksport/article/details/116848645