首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP: Curl仍然没有返回源码

PHP: Curl仍然没有返回源码
EN

Stack Overflow用户
提问于 2017-06-28 09:23:37
回答 2查看 78关注 0票数 0

我现在已经尝试了很多不同的解决方案,但这些卷曲设置都不起作用……我只想把网页的源码拿回来...

是的,我知道有file_get_contents()。但是我需要并且想要使用file_get_contents()的curl实例。错误在哪里?如何使用curl获取网页内容?

代码语言:javascript
复制
$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始终为空...即使我将变量保存到文本文件中...这张图片证明了这一点!

Picture

致以问候和感谢!

EN

回答 2

Stack Overflow用户

发布于 2017-06-28 09:30:03

请转储curl_error($curl)。然后你会得到"SSL certificate problem: unable to get local issuer certificate"

您只需设置以下选项即可避免此错误:

代码语言:javascript
复制
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

警告:上述解决方案禁用了SSL验证,并且不安全。一个安全的解决方案是设置cURL的认证:

代码语言:javascript
复制
curl_setopt ($curl, CURLOPT_CAINFO, "PATH_TO/cacert.pem");
票数 0
EN

Stack Overflow用户

发布于 2017-06-28 10:15:16

代码语言:javascript
复制
            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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44792257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档