file_get_content():SSL操作失败,代码1。

file_get_content():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行结束时出现以下错误:

  • 警告:file_get_content():ssl操作在代码1中失败。OpenSSL错误消息:错误:14090086:ssl routines:SSL3_GET_SERVER_CERTIFICATE:certificate验证在第2行的.php中失败
    • 警告:file_get_content():未能在第2行的.php中启用密码
    • 警告:file_get_content(

      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

      ):打开流失败:在第2行的.php中操作失败

我们使用的是Gentoo服务器。我们最近升级到PHP版本5.6。这个问题是在升级之后出现的。

我发现当我用一个地址替换REST服务时https://www.google.com我的页面工作得很好。

在我之前的一次尝试中“verify_peer”=>false,并将其作为参数传递给file_get_content,如下所述:忽略验证_peer=>false?但正如作者所指出的,这并没有什么不同。

我问过我们的服务器管理员之一,php.ini文件中的这些行是否存在:

  • 扩展名=php_openssl.dll
  • 允许url_fopen=on

他告诉我,既然我们在Gentoo上,在构建时就会编译OpenSSL;而且它没有设置在php.ini文件中。

我也证实allow_url_fopen起作用了。由于这个问题的特殊性,我找不到很多需要帮助的信息。你们中有谁遇到过这样的事吗?谢谢。


慕后森
浏览 823回答 3
3回答

侃侃无极

您可以通过编写使用curl的自定义函数来解决这个问题,如下所示:function&nbsp;file_get_contents_curl(&nbsp;$url&nbsp;)&nbsp;{ &nbsp;&nbsp;$ch&nbsp;=&nbsp;curl_init(); &nbsp;&nbsp;curl_setopt(&nbsp;$ch,&nbsp;CURLOPT_AUTOREFERER,&nbsp;TRUE&nbsp;); &nbsp;&nbsp;curl_setopt(&nbsp;$ch,&nbsp;CURLOPT_HEADER,&nbsp;0&nbsp;); &nbsp;&nbsp;curl_setopt(&nbsp;$ch,&nbsp;CURLOPT_RETURNTRANSFER,&nbsp;1&nbsp;); &nbsp;&nbsp;curl_setopt(&nbsp;$ch,&nbsp;CURLOPT_URL,&nbsp;$url&nbsp;); &nbsp;&nbsp;curl_setopt(&nbsp;$ch,&nbsp;CURLOPT_FOLLOWLOCATION,&nbsp;TRUE&nbsp;); &nbsp;&nbsp;$data&nbsp;=&nbsp;curl_exec(&nbsp;$ch&nbsp;); &nbsp;&nbsp;curl_close(&nbsp;$ch&nbsp;); &nbsp;&nbsp;return&nbsp;$data;}那就用file_get_contents_curl而不是file_get_contents每当您调用以https开头的url时。
打开App,查看更多内容
随时随地看视频慕课网APP