我有这段代码用curl启动查询:
function curl_query($full_url, $username, $password, $payload) {
$additionalHeaders = "";
$process = curl_init($full_url);
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', $additionalHeaders));
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_POSTFIELDS, $payload);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($process, CURLOPT_MAXREDIRS, 4);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, FALSE);
$return = curl_exec($process);
if ($return === false) {
error_log("CURL error ".curl_error($process));
}
return $return;
}
选项CURLOPT_SSL_VERIFYPEER设置为false,因此我可以读取具有自签名证书的页面。但是,当我针对https URL执行此代码时,出现错误:
CURL error SSL: certificate subject name 'localhost' does not match target host name '192.168.1.1',
我在安装了php53软件包的CentOS 5服务器上运行此代码。
提前致谢
答案 0 :(得分:39)
curl_setopt($process, CURLOPT_SSL_VERIFYHOST, FALSE);
我意识到,PHP文档的英文版缺少这些重要信息:
(翻译自PHP手册的德语版本)
如果已停用CURLOPT_SSL_VERIFYPEER,则必须将CURLOPT_SSL_VERIFYHOST设置为true或false。
答案 1 :(得分:0)
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($process,CURLOPT_SSL_VERIFYHOST, FALSE);
添加到行中可以帮助