21,886
社区成员
发帖
与我相关
我的任务
分享
$host="www.renren.com";
$request="GET / HTTP/1.1\r\nAccept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, */*\r\nAccept-Language: zh-cn\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)\r\nAccept-Encoding: gzip, deflate\r\nHost: www.renren.com\r\nConnection: Keep-Alive\r\nCookie: _r01_=1; depovince=GW\r\n\r\n";
$fp=fsockopen($host,80);
fputs($fp,$request);
$result="";
while(!feof($fp)){
$result.=fgets($fp,1024);
}
fclose($fp);
echo $result;
header("content-type:text/html;charset=utf-8");
$host="www.renren.com";
$request="GET / HTTP/1.1\r\n"
."Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, */*\r\n"
."Accept-Language: zh-cn\r\n"
."User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)\r\n"
."Accept-Encoding: gzip, deflate\r\n"
."Host: www.renren.com\r\n"
."Connection:close\r\n"
."Cookie: _r01_=1; depovince=GW\r\n\r\n";
$fp=fsockopen($host,80);
fputs($fp,$request);
$result="";
while(!feof($fp)){
$result.=fgets($fp,1024);
}
fclose($fp);
$hb = explode("\r\n\r\n",$result);//分隔http head和body
$body = $hb[1]; //http body
$chunk = strtok($body,"\r\n");//获取第一个chunked string的16进制串长标识
while( $len = (hexdec($chunk) + 0) ) //最后一个chunked string的串长铁定是0,这是协议规范
{
$start = strlen($chunk) + 2;//从chunked标识后读取串, +2是因为还要考虑"\r\n"
$bd .= substr($body , $start , $len );//读取真正要decode的http body
$body = substr($body , $start + $len + 2); //body把上一个chunked去掉
$chunk = strtok($body,"\r\n");//查找下一个chunked长度标识
}
echo gzinflate(substr($bd,10));//忽略前10个字符