php - 如何解决php中的对等证书错误
问题描述
尝试使用file_get_contents()
下面的代码片段在 Laravel PHP 中获取文件的内容。该代码在我的本地服务器上运行良好,但当我上传到生产服务器时,我收到以下错误:
ErrorException: file_get_contents(): Peer certificate CN='one46.com' 与预期的 CN='one46.comhttp' 不匹配
$verification_request['face'] = [
'proof' => base64_encode(file_get_contents($this->faceFile))
];
在代码片段中,$this->faceFile 是对文件 URL 的引用。
解决方案
如果通过 HTTP 使用 file_get_contents,您可以通过上下文设置许多连接选项。其中之一是忽略 SSL 问题。尝试这个:
$context = stream_context_create([
"ssl" => [
"verify_peer" => FALSE,
"verify_peer_name" => FALSE,
],
"http" => [
"ignore_errors" => TRUE,
],
]);
file_get_contents($theURL, NULL, $context);
推荐阅读
- c# - 如何解决从 UWP 应用程序读取文件时 Permission denied 的问题?
- java - 让 Thymeleaf 读取对象模型数组
- amazon-web-services - CloudWatch 日志定价混乱
- python - 运行 npm install 时,使用 pxssh 建立的 ssh 连接会中断。为什么?
- c# - 在用于连接两个表的 SQL 查询中插入值
- excel - 当后续行中的单元格填写完成任务的人的ID时,如何在开始时间旁边的单元格中输入任务的“结束时间”?
- android - 无法为 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 类型的对象设置未知属性“实现”
- javascript - Puppeteer:让浏览器看起来不像机器人/脚本
- python - 如何仅从python中的字符串中获取整数部分?
- android - Install new version of Android app programmatically