0
我剛剛使用cURL和https。我想向https頁面發出GET請求。我連接成功,但我沒有得到我要求的網頁。我得到的是一個HTTP 200響應和0字節。https GET請求使用CURL PHP連接,但does not不迴應
我試過使用HTTP嗅探器來調試我的HTTP會話。此外,我已將我的目標網站上的證書保存在我的服務器上。我究竟做錯了什麼?
此外,以下從Can't connect to HTTPS site using cURL. Returns 0 length content instead. What can I do?
我去了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);
}