【问题标题】:I had a errors with Curl and SSL certificate我在使用 Curl 和 SSL 证书时出错
【发布时间】:2013-02-18 13:15:58
【问题描述】:

我遇到了问题。当您向 HTTPS 发送带有 CURL 库的 POST 请求时,收到错误:SSL 证书问题,请验证 CA 证书是否正常。详细信息:错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败。 使用当前证书。 我尝试了来自 http://www.startssl.com/certs/ 和 FROM http://curl.haxx.se/docs/caextract.html 的各种证书 告诉我错误的原因可能是什么? 这是 POST 请求的代码:

        curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
    curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
    curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
    curl_setopt($process, CURLOPT_ENCODING , '');
    curl_setopt($process, CURLOPT_CONNECTTIMEOUT, 120); 
    curl_setopt($process, CURLOPT_TIMEOUT, 120);
    curl_setopt($process, CURLOPT_PROXY,$this->proxy);
    curl_setopt($process, CURLOPT_POSTFIELDS, $data);
    curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($process, CURLOPT_POST, 1);
    curl_setopt($process,CURLOPT_VERBOSE,1);

    if($ssl){
        curl_setopt ($process, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt ($process, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($process ,CURLOPT_CAINFO, YiiBase::getPathOfAlias('webroot').'/files/GTECyberTrustGlobalRoot.crt');
    }
    curl_setopt ($process, CURLOPT_HTTPHEADER, array('Expect:'));
    $return = curl_exec($process);

    $this->error_code = curl_getinfo($process,  CURLINFO_HTTP_CODE);

【问题讨论】:

  • 您是否尝试过使用自签名证书?
  • 根据这篇文章:unitstep.net/blog/2009/05/05/… 启用 SSL 时您执行的操作过多。如果将CURLOPT_SSL_VERIFYPEER设置为false,则无需设置CURLOPT_CAINFOCURLOPT_SSL_VERIFYHOST
  • 是的,通过浏览器访问该站点,我尝试通过浏览器发送请求存储证书并在发出请求时使用它,结果相同
  • 此外,CURLOPT_SSL_VERIFYHOST 似乎采用整数 (0, 1, 2) 而不是布尔值。
  • curl_setopt ($process, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt ($process, CURLOPT_SSL_VERIFYHOST, 2);还是不行

标签: php ssl curl


【解决方案1】:

这是一个工作示例。您应该查看您的选项(减少测试选项的数量)并将CURLOPT_SSL_VERIFYPEER 设置为 false 以禁用 CA 检查。

// connect via SSL, but don't check cert
$handle=curl_init('https://www.google.com');
curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($handle);

echo $content; // show target page

查看HERE

【讨论】:

猜你喜欢
  • 2010-10-18
  • 2012-09-17
  • 1970-01-01
  • 2015-04-29
  • 2011-10-31
  • 2017-11-21
  • 2018-02-19
  • 2018-01-10
  • 2015-06-05
相关资源
最近更新 更多