OPENSSL file_get_contents(): Failed to enable crypto

前端 未结 2 799
渐次进展
渐次进展 2020-11-27 04:46

I\'m building a personal stock platform (not distributed). A component I would like to have is the EPS graph on this page:

https://eresearch.fidelity.com/eresearch/e

相关标签:
2条回答
  • 2020-11-27 05:23

    Ok I have found a solution. The problem is that the site uses SSLv3. And I know that there are some problems in the openssl module. Some time ago I had the same problem with the SSL versions.

    <?php
    function getSSLPage($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSLVERSION,3); 
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }
    
    var_dump(getSSLPage("https://eresearch.fidelity.com/eresearch/evaluate/analystsOpinionsReport.jhtml?symbols=api"));
    ?>
    

    When you set the SSL Version with curl to v3 then it works.

    Edit:

    Another problem under Windows is that you don't have access to the certificates. So put the root certificates directly to curl.

    http://curl.haxx.se/docs/caextract.html

    here you can download the root certificates.

    curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . "/certs/cacert.pem");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    

    Then you can use the CURLOPT_SSL_VERIFYPEER option with true otherwise you get an error.

    0 讨论(0)
  • 2020-11-27 05:44

    Had same problem - it was somewhere in the ca certificate, so I used the ca bundle used for curl, and it worked. You can download the curl ca bundle here: https://curl.haxx.se/docs/caextract.html

    For encryption and security issues see this helpful article:
    https://www.venditan.com/labs/2014/06/26/ssl-and-php-streams-part-1-you-are-doing-it-wrongtm/432

    Here is the example:

        $url = 'https://www.example.com/api/list';
        $cn_match = 'www.example.com';
    
        $data = array (     
            'apikey' => '[example api key here]',               
            'limit' => intval($limit),
            'offset' => intval($offset)
            );
    
        // use key 'http' even if you send the request to https://...
        $options = array(
            'http' => array(
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                'method'  => 'POST',                
                'content' => http_build_query($data)                
                )
            , 'ssl' => array(
                'verify_peer' => true,
                'cafile' => [path to file] . "cacert.pem",
                'ciphers' => 'HIGH:TLSv1.2:TLSv1.1:TLSv1.0:!SSLv3:!SSLv2',
                'CN_match' => $cn_match,
                'disable_compression' => true,
                )
            );
    
        $context  = stream_context_create($options);
        $response = file_get_contents($url, false, $context);
    

    Hope that helps

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