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

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

 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值