php curl https请求ssl版本问题
https://stackoverflow.com/questions/14078182/openssl-file-get-contents-failed-to-enable-crypto
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);
//这里设置ssl版本, 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.
ssl版本对应:
/**
* One of <b>CURL_SSLVERSION_DEFAULT</b> (0), <b>CURL_SSLVERSION_TLSv1</b> (1), <b>CURL_SSLVERSION_SSLv2</b> (2), <b>CURL_SSLVERSION_SSLv3</b> (3),
* <b>CURL_SSLVERSION_TLSv1_0</b> (4), <b>CURL_SSLVERSION_TLSv1_1</b> (5) or <b>CURL_SSLVERSION_TLSv1_2</b> (6).
* The maximum TLS version can be set by using one of the <b>CURL_SSLVERSION_MAX_*</b> constants.
* It is also possible to OR one of the <b>CURL_SSLVERSION_*</b> constants with one of the <b>CURL_SSLVERSION_MAX_*</b> constants.
* <b>CURL_SSLVERSION_MAX_DEFAULT</b> (the maximum version supported by the library), <b>CURL_SSLVERSION_MAX_TLSv1_0</b>, <b>CURL_SSLVERSION_MAX_TLSv1_1</b>,
* <b>CURL_SSLVERSION_MAX_TLSv1_2</b>, or <b>CURL_SSLVERSION_MAX_TLSv1_3</b>.
* @link https://www.php.net/manual/en/function.curl-setopt.php
*/
define ('CURLOPT_SSLVERSION', 32);
如何查看请求网站的ssl版本,可以通过chrome开发者工具查看,设置对应的ssl版本就行了

浙公网安备 33010602011771号