php使用curl无法获取https网页内容的解决办法
方法1:
1 2 3 4 5 6 7 8 |
$url = "https://www.baidu.com/"; $ch = curl_init(); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch,CURLOPT_CAINFO, dirname(__FILE__).'/cacert.pem'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); |
方法2:
通过设置php.ini文件,可以一劳永逸
openssl.cafile= “C:/WebServ/php7.4.4/cacert.pem”
cacert.pem下载地址:http://curl.haxx.se/ca/cacert.pem