繁体   English   中英

PHP Curl和HTTPS无法正常工作

[英]PHP Curl & HTTPS not working

因此,我使用PHP和Curl尝试下载https weburl(从https://www.g2crowd.com ),但无法正常工作,这是我到目前为止的代码,其中一个是简单的curl,另一个是更高级的curl,两者都不工作鞍。 :(

// connect via SSL, but don't check cert
$ch=curl_init('https://www.g2crowd.com');
curl_setopt ($ch, CURLOPT_CAINFO, "cacert.pem");
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);  

$content = curl_exec($ch);

echo $content; // show target page
$ckfile = tempnam ("/tmp", 'cookiename');

$url='https://www.g2crowd.com/';
//$url='https://www.google.com';

$ch = curl_init();
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $ckfile );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $ckfile ); 

curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = [
'Host: www.g2crowd.com',
'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: en-US,en;q=0.5',
'Accept-Encoding: gzip, deflate'    
];
curl_setopt($ch, CURLOPT_CAINFO, 'C:\Users\ivan\Downloads\cacert.pem');

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, "https://www.g2crowd.com/users/c190d528-ab02-4cb5-8467-9362ceaec290");

curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$server_output = curl_exec ($ch);
if(curl_error($ch))
{
    echo curl_error($ch);
}
else {
    echo 'eureka!';
}

curl_close ($ch);

我试图捕获curl错误,所以这是什么错误:

1407742E:SSL例程:SSL23_GET_SERVER_HELLO:tlsv1警报协议版本

请尽我所能帮助我!

谢谢 !!

您的openssl程序已过期。 我也在OSX版本本机上看到了这一点。 如果您使用的是Mac,则需要下载其他的openssl 或者,以0打开SSL表示您没有使用SSL打开。

这应该可以解决您的问题:

$url='https://www.g2crowd.com/';

$ch = curl_init();

curl_setopt( $ch, CURLOPT_AUTOREFERER, TRUE );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE );

$server_output = curl_exec( $ch );

curl_close( $ch );

如果那不起作用,请尝试:

$url='https://www.g2crowd.com/';
$server_output = file_get_contents( $url );

暂无
暂无

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

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