php – file_get_contents():SSL操作失败,代码为1,无法启用加密

我一直在尝试从我在服务器上创建的PHP页面访问这个特定的REST服务.我将问题缩小到这两行.所以我的PHP页面如下所示:

<?PHP
$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");

echo $response; ?>

页面在第2行死亡,并出现以下错误

  • Warning: file_get_contents(): SSL operation Failed with code 1.
    OpenSSL Error messages: error:14090086:SSL
    routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify Failed in
    PHP on line 2

解决方法:

这是一个非常有用的链接,可以找到:

http://php.net/manual/en/migration56.openssl.php

一篇官方文档,描述了在PHP 5.6中打开ssl所做的更改
从这里我学到了另一个我应该设置为false的参数:“verify_peer_name”=> false

Note: This has very significant security implications. disabling verification potentially permits a 07001 to use an invalid certificate to eavesdrop on the requests. While it may be useful to do this in local development, other approaches should be used in production.

所以我的工作代码如下所示:

<?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; ?>

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...