总有人间一两风,填我十万八千梦

Warning: file_get_contents(): SSL operation failed with code 1的解决方案

PHP Zero、J 1987℃ 0评论

PHP使用file_get_contents() 读取HTTPS的时候报了如下的警告:

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in ….

Warning: file_get_contents(): Failed to enable crypto in….

Warning: file_get_contents(https:….

解决方案

把SSL证书验证关闭即可,代码示例如下:

<?php
$arrContextOptions=array(
    "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
); 
$response = file_get_contents("https://translate.google.cn/", 
                             false,
                             stream_context_create($arrContextOptions)
                            );
echo $response; 
?>

转载请注明:悠然品鉴 » Warning: file_get_contents(): SSL operation failed with code 1的解决方案

喜欢 (0)or分享 (0)
发表我的评论
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址