php get请求返回空

php get请求返回空,php,curl,Php,Curl,file_get_contents在url上返回一个空字符串: 当它明显不是空的时候。 也试过卷曲,这是我的代码 $ch = curl_init(); $cookieFile = 'cookies.txt'; curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);

file_get_contents在url上返回一个空字符串:

当它明显不是空的时候。 也试过卷曲,这是我的代码

$ch = curl_init();
$cookieFile = 'cookies.txt';
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');

$url = 'http://thepiratebay.org/search/a';
curl_setopt($ch, CURLOPT_URL,$url);

$html = curl_exec ($ch);
var_dump($html);
$html = file_get_contents($url);
var_dump($html);

curl_close ($ch); unset($ch);
输出为:

string(143) "HTTP/1.1 200 OK
X-Powered-By: PHP/5.3.8
Content-type: text/html
Content-Length: 0
Date: Mon, 14 Nov 2011 20:27:01 GMT
Server: lighttpd

"
string(0) ""
如果我将url更改为“http://thepiratebay.org/search“通过删除2个字符,一切正常,我得到了良好的响应


有什么想法吗?

问题是您试图使用
CURLOPT\u TIMEOUT
设置用户代理字符串。尝试使用
CURLOPT_USERAGENT
,这将解决您的问题。您可以同时使用或(如果您更愿意使用
file\u get\u contents
)执行此操作


所有这三种技术的示例都可以在上找到。

文件获取内容
可能无法在安装中打开URL。看见或者,Piratebay.org可能会因为
文件\u get\u contents
调用中的用户代理而阻止您。试着通过一个测试。或者它没有返回任何内容,因为您没有像使用
curl
一样在
文件中发送任何cookies\u get\u contents
调用。一句话,即使URL相同,请求也不同。

lolz,愚蠢的错误,ty,是CURLOPT_用户代理,我最后用python写了这个:)