使用CURL读取SSL页面(php) [英] reading SSL page with CURL (php)
问题描述
我试图使用php和curl库下载安全(使用https)网页的内容。
但是,读取失败,我收到错误60: SSL证书问题,请验证CA证书是否正确。
也详细信息:SSL3_GET_SERVER_CERTIFICATE:证书验证失败
所以...很自我解释错误msg的。
我的问题是:如何发送SSL证书(正确的?验证它并让我进来?
此外,这里是我的选项数组,如果你想知道:
$ options = array(
CURLOPT_RETURNTRANSFER => true,//返回网页
CURLOPT_HEADER => false,//不返回标题
CURLOPT_FOLLOWLOCATION => true,//追踪重定向
CURLOPT_ENCODING =>,//处理所有编码
CURLOPT_USERAGENT =>Mozilla / 5.0(Windows; U; Windows NT 5.1; en-US; rv:xxx)Gecko / 20041107 Firefox / xx,// who am i
CURLOPT_AUTOREFERER => true,// set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120,// timeout on connect
CURLOPT_TIMEOUT => 120,//响应时超时
CURLOPT_MAXREDIRS => 10,//在10次重定向后停止
CURLOPT_SSL_VERIFYHOST => 1,
);
任何建议都很棒,
Andrew解决方案听起来你可能会误解错误,它看起来像我正在连接的网站是自签名或其他一些常见的问题,就像一般的浏览器警告,你
您需要设置
CURLOPT_SSL_VERIFYPEER
和CURLOPT_SSL_VERIFYHOST
到FALSE
这应该禁用两个主要的检查,它们可能不是必需的,但这至少应该让你去
要清楚,此操作会禁用旨在保护您的功能。
有关PHP网站的更多信息: curl_setopt()
I am trying to download the content of a secure (uses https) webpage using php and curl libraries.
However, reading failed and I get error 60: "SSL certificate problem, verify that the CA cert is OK."
also "Details: SSL3_GET_SERVER_CERTIFICATE:certificate verify failed"
So...pretty self explanatory error msg's.
My question is: How do I send an SSL certificate (the right one?) and get this page to verify it and let me in?
Also, here is my options array in case you are wondering:
$options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:x.x.x) Gecko/20041107 Firefox/x.x", // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects CURLOPT_SSL_VERIFYHOST => 1, );
Any suggestions would be great, Andrew
解决方案It sounds like you might be misinterpreting the error. It looks to me like the site you're connecting to is self-signed or some other common problem. Just like the usual browser warning, you're easiest work around is to disable the checks.
You'll need to set
CURLOPT_SSL_VERIFYPEER
andCURLOPT_SSL_VERIFYHOST
toFALSE
. This should disable the two main checks. They may not both be required, but this should at least get you going.To be clear, this disables a feature designed to protect you. Only do this if you have verified the certificate and server by some other means.
More info on the PHP site: curl_setopt()
这篇关于使用CURL读取SSL页面(php)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!