【问题标题】:How to resolve peer certificate error in php如何解决php中的对等证书错误
【发布时间】:2020-07-24 16:24:57
【问题描述】:

尝试使用file_get_contents() 在 Laravel PHP 中获取文件的内容,如下面的 sn-p 所示。代码在我的本地服务器上运行良好,但当我上传到生产服务器时,我收到以下错误:

ErrorException: file_get_contents(): Peer certificate CN='one46.com' 与预期的 CN='one46.comhttp' 不匹配

$verification_request['face'] = [
   'proof' => base64_encode(file_get_contents($this->faceFile))
];

在代码中sn-p $this->faceFile 是对文件URL 的引用。

【问题讨论】:

  • $this->faceFile 包含什么?您谈论的是一个文件,但您显然是在建立网络连接:-?
  • $this->face 文件包含一个图像文件的 url

标签: php laravel ssl


【解决方案1】:

如果通过 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);

【讨论】:

    猜你喜欢
    • 2019-10-07
    • 1970-01-01
    • 2012-10-02
    • 2016-12-07
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多