【发布时间】:2017-01-07 14:45:01
【问题描述】:
使用下面的代码我没有收到任何错误或内容。
我有兴趣获取我的网站http://www.aptamitra.in 的内容。
$cookie = tempnam ("/tmp", "CURLCOOKIE");
$ch = curl_init();
//$timeout = 5;
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
curl_setopt( $ch, CURLOPT_URL, "http://www.aptamitra.in" );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, "" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls
//curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
//curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
//curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
$content = curl_exec( $ch );
$response = curl_getinfo( $ch );
var_dump($content);
echo "<pre>";
print_r($response); // iam getting response here.
curl_close ( $ch );
我使用var_dump($content)print_r($response)得到的数组如下所示
不知道为什么没有内容。
【问题讨论】:
-
您收到 302 重定向,因此没有内容,但您打开了 CURLOPT_FOLLOWLOCATION,它应该遵循该重定向。令人费解!
-
@sherif,是的,我没有收到内容或错误消息
-
回声 curl_error($ch);在 curl_exec() 之前粘贴;并知道错误
-
是的@jedifans 它在
-
如果您尝试加载
http://www.aptamitra.in/而不是http://www.aptamitra.in会发生什么? (所以,以 / 结尾)