gpt4 book ai didi

php - OPENSSL file_get_contents() : Failed to enable crypto

转载 作者:IT王子 更新时间:2023-10-29 01:02:18 27 4
gpt4 key购买 nike

我正在构建一个个人股票平台(未分发)。我想要的一个组件是此页面上的 EPS 图:

https://eresearch.fidelity.com/eresearch/evaluate/fundamentals/earnings.jhtml?stockspage=earnings&symbols=AAPL&showPriceLine=yes

如你所见,页面是 https,所以经过几天的努力,我启用了 openssl,现在它似乎适用于所有 https 页面,例如 facebook 和 twitter 的主页,但它仍然无法满足我的需求。

file_get_contents('https://facebook.com'); /* works */
file_get_contents('https://twittercom'); /* works */
file_get_contents('https://eresearch.fidelity.com/eresearch/evaluate/fundamentals/earnings.jhtml?stockspage=earnings&symbols=AAPL&showPriceLine=yes');

我收到警告:

Warning: file_get_contents(): SSL: crypto enabling timeout in C:\xampp\htdocs\index.php on line 3
Warning: file_get_contents(): Failed to enable crypto in C:\xampp\htdocs\index.php on line 3
Warning: file_get_contents(https://eresearch.fidelity.com/eresearch/evaluate/fundamentals/earnings.jhtml?stockspage=earnings&symbols=AAPL&showPriceLine=yes): failed to open stream: operation failed in C:\xampp\htdocs\index.php on line 3
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\index.php on line 3

我能看到的唯一区别是保真度页面在 https 标签附近有一个三角形。

fidelity https label

最佳答案

好的,我找到了解决方案。问题是该站点使用 SSLv3。而且我知道openssl模块有一些问题。前段时间我在 SSL 版本上遇到了同样的问题。

<?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"));
?>

当您使用 curl 将 SSL 版本设置为 v3 时,它就可以工作了。

编辑:

Windows 下的另一个问题是您无权访问证书。所以直接把根证书放到curl上。

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

在这里您可以下载根证书。

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

然后您可以将 CURLOPT_SSL_VERIFYPEER 选项与 true 一起使用,否则会出现错误。

关于php - OPENSSL file_get_contents() : Failed to enable crypto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14078182/

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