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;