gpt4 book ai didi

php - get_headers() : SSL operation failed with code 1

转载 作者:可可西里 更新时间:2023-10-31 23:06:01 28 4
gpt4 key购买 nike

嘿,我试着获取 url 的标题信​​息,

当我使用协议(protocol) http 时它工作正常,但是当我使用 https 时它不工作

网址:https://200.35.78.130/

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
Warning: get_headers(): Failed to enable crypto in
Warning: get_headers(https://200.35.78.130/): failed to open stream: operation failed in /

这是我的代码

print_r(get_headers("https://200.35.78.130/", 1));

最佳答案

当您尝试访问没有有效 SSL 证书的 URL 时会发生该错误。您可以通过 overriding the default stream context 解决此问题,这将影响所有后续文件操作(包括远程 URL)

<?php
stream_context_set_default( [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);

print_r(get_headers('https://200.35.78.130/'));

或者,如果您使用的是 PHP 7.1+,则可以使用 stream_context_create 创建临时上下文并将其直接传递给函数,以避免覆盖默认值:

$context = stream_context_create( [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);

print_r(get_headers('https://200.35.78.130/', 0, $context));

感谢 Matthijs Wessels 在评论中指出这一点。

关于php - get_headers() : SSL operation failed with code 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37274206/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com