的file_get_contents返回的URL爲空字符串:當它是obviosly不是空http://thepiratebay.org/search/aPHP的GET請求返回空
。 也試過嫋嫋,我的繼承人代碼
$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個字符一切正常,並我得到了很好的迴應。
什麼想法?
lolz,愚蠢的錯誤,ty,這是CURLOPT_USERAGENT,我結束了在python中寫這個:) – Legion