0

I'm new to using cURL and https. I want to make a GET request to a https page. I connect successfully but I do not get the page I requested. All I get is a HTTP 200 response and 0 bytes.

I've tried debugging my HTTP conversation using a HTTP sniffer. Also I've saved the cert from my target site on my server. What am I doing wrong?

Also, following the advice from Can't connect to HTTPS site using cURL. Returns 0 length content instead. What can I do?

I've gone to http://curl.haxx.se/ca/cacert.pem, downloaded the cert and linked it in my code

$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);
}
Community
  • 1
  • 1
user1801060
  • 2,733
  • 6
  • 25
  • 44

1 Answers1

0

It works perfectly well. However, HTTP sniffers(especially Fiddler) do not seem able to decrypt cURL traffic. To test out my responses, I printed out $page and I got the pages I expected.

user1801060
  • 2,733
  • 6
  • 25
  • 44