简体   繁体   English

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

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

I'm new to using cURL and https. 我是使用cURL和https的新手。 I want to make a GET request to a https page. 我想向https页面发出GET请求。 I connect successfully but I do not get the page I requested. 我连接成功,但是没有得到我请求的页面。 All I get is a HTTP 200 response and 0 bytes. 我得到的只是一个HTTP 200响应和0个字节。

I've tried debugging my HTTP conversation using a HTTP sniffer. 我尝试使用HTTP嗅探器调试HTTP会话。 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. 另外,请遵循“ 无法使用cURL连接到HTTPS站点”中的建议 Returns 0 length content instead. 而是返回0长度的内容。 What can I do? 我能做什么?

I've gone to http://curl.haxx.se/ca/cacert.pem , downloaded the cert and linked it in my code 我去了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);
}

It works perfectly well. 它运作良好。 However, HTTP sniffers(especially Fiddler) do not seem able to decrypt cURL traffic. 但是,HTTP嗅探器(尤其是Fiddler)似乎无法解密cURL流量。 To test out my responses, I printed out $page and I got the pages I expected. 为了测试我的回答,我打印了$ page,然后得到了预期的页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM