php下载https图片报错Failed to enable crypto

file_get_contents下载一个https图片,报错如下

Warning: file_get_contents(): Failed to enable crypto

failed to open stream: operation failed in

已经在php.ini 打开openssl扩展和 fopen url

在phpinfo里面检查已经正确开启

    $arrContextOptions=array(
        "ssl"=>array(
            "verify_peer"=>false,
            "verify_peer_name"=>false,
        ),
    ); 
    // return file_get_contents($url);
    return file_get_contents($url, false, stream_context_create($arrContextOptions));
    

使用这段代码同样无效,仍然报此错误

阅读 4.9k
1 个回答

证书错误,试试指定证书,下载证书 放置在程序可访问目录

$options = [
    "ssl" => [
        'cafile' => "/path/to/file/cacert.pem", // cacert.pem文件存放的目录
    ]
];
return file_get_contents($url, false, stream_context_create($options));
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题