Joh*_*ith 37 php apache openssl
我正在建立一个个人股票平台(未分发).我想要的组件是此页面上的EPS图表:
正如你所看到的那样,页面是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');
Run Code Online (Sandbox Code Playgroud)
我收到了警告:
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
Run Code Online (Sandbox Code Playgroud)
我能看到的唯一区别是保真度页面在https标签附近有一个三角形.

Ren*_*hle 53
好的,我找到了解决方案.问题是该站点使用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"));
?>
Run Code Online (Sandbox Code Playgroud)
当您将带有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);
Run Code Online (Sandbox Code Playgroud)
然后你可以使用该CURLOPT_SSL_VERIFYPEER选项,true否则你会收到错误.
小智 5
遇到了同样的问题-它在ca证书中的某个位置,所以我使用了用于卷发的ca束,并且它起作用。您可以在此处下载curl ca捆绑包:https: //curl.haxx.se/docs/caextract.html
有关加密和安全性问题,请参阅以下有用的文章:https :
//www.venditan.com/labs/2014/06/26/ssl-and-php-streams-part-1-you-are-doing-it-wrongtm/ 432
这是示例:
$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);
Run Code Online (Sandbox Code Playgroud)
希望能有所帮助
小智 5
对我有用的解决方法是禁用对等验证。使用它时要小心,因为它不应该在生产中使用。
$arrContextOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
)
);
$context = stream_context_create($arrContextOptions);
$contents = file_get_contents($url,false,$context);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
105953 次 |
| 最近记录: |