php get_headers 报错 get_headers(): SSL operation failed with code 1. OpenSSL Error messages

18-08-16 13:12 字数 529 阅读 4039 已编辑

使用 get_headers 函数获取请求头时,报了下面的错。

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

这是因为你访问的URL没有有效的ssl证书

That error occurs when you're trying to access a URL without a valid SSL certificate. You can work around this by overriding the default stream context, which will affect all subsequent file operations (including remote URLs)

解决办法

在get_headers前增加下面的代码

stream_context_set_default( [
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
    ],
]);
$headers = get_headers($httpPath, 1);
1人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论
站长 @ 十七度
文章
380
粉丝
23
喜欢
191
收藏
31
排名 : 1
访问 : 130万
私信