当前位置:首页 > 电脑知识 > 正文内容

干货分享(php file_get_contents curl)php file_get_contents post,php file_get_contents(): SSL operation failed with code 1. OpenSSL Error message.....,php file_get_contents(): SSL operation failed with code 1. OpenSSL Error message.....,

sauo3年前 (2022-09-17)电脑知识162

在调试php脚本代码时,发现使用 file_get_contents() 函数请求HTTPS的网址链接时出现了报错,其报错代码如下面所示“file_get_contents(): SSL operation failed with code 1. OpenSSL Error message...”百度查了一下原因与解决方法,下面就来分享一下。

原因:

服务器上未能正确配置好https证书,所以出现了错误。

解决方法:

方法1:

(1)、下载证书,http://curl.haxx.se/ca/cacert.pem

(2)、证书上传到服务器,并记录好上传的路径

(3)、打开php的配置文件,php.ini

(4)、修改 openssl.cafile 的配置的值为上传的证书地址即可

例:

PHP
openssl.cafile = "/etc/ssl/certs/cacert.pem"复制

(5)、重启 php 即可

方法2:

直接对 file_get_contents 函数进行设置,让 file_get_contents 函数跳过https验证,暂时解决问题

例:

PHP
# feiniaomy.com 飞鸟慕鱼博客 $url = 请求地址; $arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, "allow_self_signed"=>true, ), ); $response = file_get_contents($url, false, stream_context_create($arrContextOptions));复制

方法3:

使用curl来替代 file_get_contents 函数来使用!

例:

PHP
# feiniaomy.com 飞鸟慕鱼博客 $url = 请求地址; function getSSLPage($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSLVERSION,3); $result = curl_exec($ch); curl_close($ch); return $result; } var_dump(getSSLPage($url));复制

本文链接:http://blog.sauo.top/?id=271 感谢分享!

分享到:

扫描二维码推送至手机访问。

版权声明:本文由冬眠先生个人博客发布,如需转载请注明出处。

本文链接:http://blog.sauo.top/?id=271

分享给朋友:

“干货分享(php file_get_contents curl)php file_get_contents post,php file_get_contents(): SSL operation failed with code 1. OpenSSL Error message.....,php file_get_contents(): SSL operation failed with code 1. OpenSSL Error message.....,” 的相关文章

原创(禁止ping命令操作)linux如何停止ping,linux禁ping操作的方法,linux禁ping操作的方法,

免费领取腾讯云服务器! linux中可以通过ssh命令来禁止其它机器来ping自己,下面是配置方法,大家可以参考一下。 linux中禁ping的方法 方法1 临时禁ping,系统重启后失效,已在ubuntu系...

万万没想到(Ubuntu安装ssh服务)ubuntu配置ssh服务器,ubuntu安装ssh服务器的方法,ubuntu安装ssh服务器的方法,

万万没想到(Ubuntu安装ssh服务)ubuntu配置ssh服务器,ubuntu安装ssh服务器的方法,ubuntu安装ssh服务器的方法,

免费领取腾讯云服务器! 安装了一个ubuntu系统,想着在内网中用ssh进行远程连接管理。下面这篇博文就说说如果在ubuntu系统中安装ssh远程管理服务。 ubuntu 安装ssh服务器的方法 1、安装 openssh-s...

这都可以(php保存网络图片到本地)php下载图片到本地,php保存图片到本地的方法,php保存图片到本地的方法,

免费领取腾讯云服务器! 下面列几种网上收集的利用php脚本将远程图片保存至本地的方法,各位自行测试代码是否可用,另外php保存远程图片到本地并不能确保百分百的一定会拉取到远程图片的数据。 php保存远程图片到本地的方法 方法...

干货分享(php输出json中文乱码)json数据中文乱码怎么办,解决 php json中文乱码的问题,解决 php json中文乱码的问题,

免费领取腾讯云服务器! php输出使用json_encode函数生成的json数据的时候,发现数据中的中文被转义成了unicode编码,如果使用ajax请求的json数据还好一点,浏览器会自动将unicode编码转义回来,但如果直接输出到浏览器上,那就会直...

难以置信(php错误日志在哪里)PHP 日志,php设置错误日志的方法,php设置错误日志的方法,

难以置信(php错误日志在哪里)PHP 日志,php设置错误日志的方法,php设置错误日志的方法,

免费领取腾讯云服务器! php设置错误日志需要在php配置文件php.ini中设置,只需要简单的几步设置就可以实现,下面就来详细的说一下。 php设置错误日志的方法 1、打开php的配置文件,php.ini...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。