使用 CURL PHP 的 https GET 请求连接,但不返回响应


https GET request using CURL PHP connects, but does'nt return response

我是使用cURL和https的新手。我想向https页面发出GET请求。我连接成功,但没有得到我请求的页面。我得到的只是一个 HTTP 200 响应和 0 字节。

我尝试使用HTTP嗅探器调试我的HTTP对话。此外,我还将目标站点的证书保存在服务器上。我做错了什么?

此外,遵循无法使用 cURL 连接到 HTTPS 站点的建议。改为返回 0 长度内容。我能做什么?

我已经去了 http://curl.haxx.se/ca/cacert.pem,下载了证书并将其链接到我的代码中

$target = ADDR . 'xxx';
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/qld_cert.crt");
curl_setopt($ch, CURLOPT_URL, $target); // Define target site
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return page in string
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // Tell PHP/CURL where to write cookies
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); // Tell PHP/CURL which cookies to send
$page = curl_exec($ch);
if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo '';
}
// Check if any error occurred
if(curl_errno($ch))
{
    echo 'Curl error: ' . curl_error($ch);
}

它工作得很好。但是,HTTP嗅探器(尤其是Fiddler(似乎无法解密cURL流量。为了测试我的回答,我打印了$page,得到了我想要的页面。