get_headers(): SSL operation failed with code 1

前端 未结 2 1631
说谎
说谎 2021-02-19 08:10

Hey i try to get header information of url ,

when i use the protocol http it\'s work fine , but when i use https it\'s not working

the url : https://200.35.78.13

相关标签:
2条回答
  • 2021-02-19 08:26

    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)

    <?php
    stream_context_set_default( [
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ]);
    
    print_r(get_headers('https://200.35.78.130/'));
    

    Alternatively, if you're using PHP 7.1+, you can create a temporary context using stream_context_create and pass it directly to the function, to avoid overriding the default:

    $context = stream_context_create( [
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ]);
    
    print_r(get_headers('https://200.35.78.130/', 0, $context));
    

    Thanks to Matthijs Wessels in the comments for pointing it out.

    0 讨论(0)
  • 2021-02-19 08:31

    Because you installed the SSL certificate without an intermediate key

    0 讨论(0)
提交回复
热议问题