get_headers():SSL操作失败,代码为1

Ahm*_*adi 9 php

嘿,我试图获取网址的标题信息,

当我使用协议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 /
Run Code Online (Sandbox Code Playgroud)

这是我的代码

print_r(get_headers("https://200.35.78.130/", 1));
Run Code Online (Sandbox Code Playgroud)

iai*_*inn 21

当您尝试访问没有有效SSL证书的URL时,会发生该错误.您可以通过覆盖默认流上下文来解决此问题,这将影响所有后续文件操作(包括远程URL)

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

print_r(get_headers('https://200.35.78.130/'));
Run Code Online (Sandbox Code Playgroud)

  • php7 中的 get_headers 现在也可以选择将上下文作为参数。您可以使用[stream_context_create](https://www.php.net/manual/en/function.stream-context-create.php)创建上下文。 (2认同)