我现在尝试了很多不同的解决方案但是没有那些卷曲设置曾经工作过...我只想获得网页的源代码...
是的,我知道有file_get_contents()
。但我需要并且想要使用file_get_contents()
的curl instand。错误在哪里?如何通过curl获取网页内容?
$url = "https://google.de";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($curl, CURLOPT_HTTPHEADER, array(
// "API-Token: " . APITOKEN . "",
// "API-Secret: " . APISECRET . "",
//));
$response = curl_exec($curl);
echo "This is the response...:\n" . $response;
$response
总是空的......即使我将变量保存到文本文件中...这里的图片证明了这一点!
问候,谢谢!
答案 0 :(得分:0)
请转储curl_error($curl)
。然后你会得到"SSL certificate problem: unable to get local issuer certificate"
。
您只需设置以下选项即可避免此错误:
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
警告:上述解决方案禁用SSL验证并且不安全。安全的解决方案是设置cURL的认证:
curl_setopt ($curl, CURLOPT_CAINFO, "PATH_TO/cacert.pem");
答案 1 :(得分:0)
If you will check error then you will show below error
if(!curl_exec($curl)){
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
Error: "SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" - Code: 60
To solve this issue you can follow this link-
https://wehavefaces.net/fixing-ssl-certificate-problem-when-performing-https-requests-in-php-e3b2bb5c58f6