没有从cURL得到任何错误消息或内容 [英] Not getting any error message or content from cURL
问题描述
使用下面的代码,我没有收到任何错误或内容。
Using the code below I'm not getting any kind of error or content.
我有兴趣获取我网站的内容 http://www.aptamitra.in 。
I'm interested in getting content of my website 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)$ c获得的数组$ c>
print_r($ response)
如下所示
bool(false)
Array
(
[url] => http://www.aptamitra.in/
[content_type] => text/html; charset=UTF-8
[http_code] => 302
[header_size] => 4956
[request_size] => 4984
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 20
[total_time] => 0.452
[namelookup_time] => 0
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => -1
[starttransfer_time] => 0.124
[redirect_time] => 0.328
[redirect_url] =>
[primary_ip] => 127.0.0.1
[certinfo] => Array
(
)
[primary_port] => 1080
[local_ip] => 127.0.0.1
[local_port] => 52230
)
我不知道为什么没有内容。
I don't know why there is no content.
推荐答案
每 curl_exec()
文档:
成功返回TRUE,失败返回FALSE。但是,如果设置了
CURLOPT_RETURNTRANSFER
选项,它将在成功时返回结果,在失败时返回FALSE。
Returns TRUE on success or FALSE on failure. However, if the
CURLOPT_RETURNTRANSFER
option is set, it will return the result on success, FALSE on failure.
您对 var_dump($ content); 的调用显示
bool(false)
,其中表示 curl_exec()
失败。这就是为什么您没有得到任何响应内容的原因。使用 curl_errno()
和/或 curl_error()
找出原因。
Your call to var_dump($content);
is showing bool(false)
, which means curl_exec()
is failing. That is why you are not getting any response content. Use curl_errno()
and/or curl_error()
to find out why it is failing.
我注意到的一件事是 curl_getinfo()
正在报告 [redirect_count] => 20
。这是很多重定向。服务器可能会陷入无限的重定向循环,并且 curl_exec()
决定在一段时间后失败。请参见 CURLOPT_MAXREDIRS
。检查报告的错误号是否为 CURLE_TOO_MANY_REDIRECTS
。
One thing I do notice is curl_getinfo()
is reporting [redirect_count] => 20
. That is a lot of redirects. The server is likely getting stuck in an endless redirect loop and curl_exec()
decides to fail after awhile. See CURLOPT_MAXREDIRS
. Check if the error number being reported is CURLE_TOO_MANY_REDIRECTS
.
这篇关于没有从cURL得到任何错误消息或内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!