我有这段代码可以使用 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 服务器上运行此代码。
提前致谢