2014-12-07 56 views
0

我正在尝试向基于https的网址发出curl请求。但似乎没有返回.. 我测试了许多非HTTPS的代理。PHP:使用代理的Https卷曲

$att = "cookie.txt"; 
$ip = "121.14.138.56:81"; 
$curl = curl_init("https://www.att.com"); 
curl_setopt($curl, CURLOPT_PROXY, $ip); 
curl_setopt($curl, CURLOPT_COOKIEJAR, $att); 
curl_setopt($curl, CURLOPT_COOKIEFILE, $att); 
curl_setopt($curl, CURLOPT_HEADER, 1); 
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/27.0.1453.94 Safari/537.36"); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 50); 
curl_setopt($curl, CURLOPT_TIMEOUT, 50); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
$reply = curl_exec($curl); 
curl_close($curl); 
echo $reply; 
+0

在你做'curl_close($卷曲);',你可以打印所有相关信息进行调试'的var_dump(curl_getinfo($卷曲));'。 – 2014-12-07 12:26:40

+0

对于https链接,我只会得到“boolean false”,因为http链接没问题。 – CrY 2014-12-07 12:39:11

+0

检查你的php安装是否用openssl('phpinfo()')编译。 – 2014-12-07 12:46:39

回答

0

似乎此代码正在工作。注:只有一些代理支持HTTPS ..

$proxy = "205.221.221.111:8080"; 
$curl = curl_init("https://www.att.com"); 
if (isset($proxy)) {curl_setopt($curl, CURLOPT_PROXY, $proxy);} 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl, CURLOPT_COOKIEJAR, $att); 
curl_setopt($curl, CURLOPT_COOKIEFILE, $att); 
curl_setopt($curl, CURLOPT_HEADER, 1); 
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/27.0.1453.94 Safari/537.36"); 
curl_setopt($curl, CURLOPT_COOKIE, 'cookie.txt'); 
curl_setopt($curl, CURLOPT_AUTOREFERER, true); 
curl_setopt($curl, CURLOPT_COOKIESESSION, true); 
curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookie.txt'); 
curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt'); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); 
curl_setopt($curl, CURLOPT_TIMEOUT, 30); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
$reply = curl_exec($curl); 
curl_close($curl); 
var_dump(curl_getinfo($curl)); 
echo $reply;