使用 CURL (php) 读取 SSL 页面 [英] reading SSL page with CURL (php)
问题描述
我正在尝试使用 php 和 curl 库下载安全(使用 https)网页的内容.
I am trying to download the content of a secure (uses https) webpage using php and curl libraries.
但是,读取失败,我收到错误 60:SSL 证书问题,请验证 CA 证书是否正确."
However, reading failed and I get error 60: "SSL certificate problem, verify that the CA cert is OK."
还有详细信息:SSL3_GET_SERVER_CERTIFICATE:证书验证失败"
also "Details: SSL3_GET_SERVER_CERTIFICATE:certificate verify failed"
所以......非常不言自明的错误消息.
So...pretty self explanatory error msg's.
我的问题是:如何发送 SSL 证书(正确的?)并获取此页面以验证它并让我进入?
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.
您需要将 CURLOPT_SSL_VERIFYPEER
和 CURLOPT_SSL_VERIFYHOST
设置为 FALSE
.这应该禁用两个主要检查.它们可能不是必需的,但这至少应该可以帮助您.
You'll need to set CURLOPT_SSL_VERIFYPEER
and CURLOPT_SSL_VERIFYHOST
to FALSE
. This should disable the two main checks. They may not both be required, but this should at least get you going.
需要明确的是,这会禁用一项旨在保护您的功能.仅当您通过其他方式验证了证书和服务器时才执行此操作.
有关 PHP 站点的更多信息:curl_setopt()
More info on the PHP site: curl_setopt()
这篇关于使用 CURL (php) 读取 SSL 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!