file_get_contents(): SSL operation failed with code 1 (certificate verify failed)

后端 未结 2 1736
陌清茗
陌清茗 2021-01-19 08:48

I have installed WAMP 3.0.4 and am trying to write a PHP script that connects to an external HTTPS web service. But this returns the error:

Warning: f

相关标签:
2条回答
  • 2021-01-19 09:09

    If you want to disable the verification of the SSL connection you can use:

    'verify_peer' => false
    

    And inside your code:

    <?php
    $auth = base64_encode('username:password');
    
    $aContext = array(
        'http' => array(
            'proxy' => 'tcp://proxyip:proxyport',
            'request_fulluri' => true,
            'header' => "Proxy-Authorization: Basic $auth"
        ),
        'ssl' => array(
            'verify_peer' => false,
        ),
    );
    $cxContext = stream_context_create($aContext);
    
    $sFile = file_get_contents("https://www.google.com", False, $cxContext);
    
    echo $sFile;
    ?>
    

    However note that this means that no-one is guarantee you that the data you get is authentic (since the ssl certificate is NOT verified).

    If you want to verify the certificate, you should use the root certificates as in your question, however, you said you work with WAMP so the path to your cafile should be something like:

    "cafile" => "c:/wamp/certificates/cacert.pem",
    

    More important - you said nothing regarding the proxy in your question. Is it something that you need or is it something you found somewhere and just trying to use?

    If you don't need the proxy just remove if from your request.

    0 讨论(0)
  • 2021-01-19 09:22

    While on MAMP on macOS, simply restarting MAMP server solved this issue for me.

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