file_get_contents wget curl 都下载不了http://nbbbs.enet.com.cn/forum-5-1.html。 每次下载的代码只有一半。 仔细比较了 ie 的http头 和 php的http头,发现就少了 Accept-Encoding: gzip, deflate

在 curl里加上

curl_setopt($ch, CURLOPT_ENCODING, "gzip, deflate");

就搞定这个了。

我的理解是,服务器强行要求客服端支持gzip

// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://nbbbs.enet.com.cn/forum-5-1.html");
curl_setopt($ch, CURLOPT_ENCODING, "gzip, deflate");
 
curl_setopt($ch, CURLOPT_HEADER, 1);
//curl_setopt($ch, CURLOPT_NOBODY, 0);
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
// grab URL and pass it to the browser
$content = curl_exec($ch);
 
// close cURL resource, and free up system resources
curl_close($ch);
 
 
file_put_contents('a.html', $content);
 
exit;
php/function/curl_gzip.txt · 最后更改: 2008/10/14 02:23 由 kenvin
到顶部
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0 红麦软件 红麦软件