如何解决gzip编码问题

youngpand 2007-04-28 05:53:04
一个网站用了gzip编码
我用fsockopen抓取那个网站的数据得到的是乱码,
怎么把gzip编码的数据还原成正常编码
其HEADER信息如下:
Server: Apache
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
Content-Encoding: gzip
Content-Length: 7295
Connection: close
Content-Type: text/html; charset=gb2312

请高手指点:如何把gzip编码的数据还原成正常编码 ?谢谢!
...全文
1052 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
tony-杨 2007-04-29
  • 打赏
  • 举报
回复
参见Zlib Compression Functions类的函数

很少用到

实在帮不了忙
iasky 2007-04-29
  • 打赏
  • 举报
回复
gzuncompress
newzy 2007-04-29
  • 打赏
  • 举报
回复
方法有三, 供大家参考:

(1) 如果是开发工具支持压缩输出(如 php, csp/eybuild 等都支持),
临时关闭压缩输出选项, (如注释掉 ebDeflateInit(TRUE); 一句即可)

(2) 如果是 webserver 开启了压缩过滤, 则打开 apache 的配置文件, 注释
掉 mod_deflate 等相关选项, 即关闭输出压缩过滤器, 重启 apache.
请参考 apache mod_deflate 相关配置.

(3) 用 httplook 抓包, 记住选中 "Decode compressed entities" 选项.
抓到压缩的数据, 它会解开显示.
结果如下例所示, "Message body has been unpacked." 即表已经解包显示.


HTTP/1.1 200 OK
Date: Sun, 29 Apr 2007 09:39:49 GMT
X-Powered-By: CSP/eybuild-2.3.0
Content-Encoding: gzip
Content-Length: 903
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html


<html>
<head>
<META content=no-cache http-equiv=pragma>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content="wed, 26 Feb 1997 08:21:57 GMT" http-equiv=expires>
<title>BBR 登录(V1.1.0)</title>
<style>
<!--
p, td, div, b { font-size: 11pt; }
td {height: 35px;}
div { color: red }
#title {font-size: 16px; color: #663300; width: 90px; }
#text { width: 150px; }
a:link {color: #000066; text-decoration: none}
a:visited {color: #000066; text-decoration: none}
a:hover {color: #FF0000; text-decoration: underline}
a:active {color: #000066; text-decoration: underline}
-->
</style>
<script language=JavaScript><!--
if (top.location !== self.location){top.location.href=self.location;}
function set_focus() {
document.forms[0].elements[1].focus();
}
-->
</script>
</head>
<body onload="set_focus();">
<p style="margin-top: 80px">
<center>
<form action="" method=post>
<table width=300 border=1 cellpadding="2" cellspacing="0" bordercolor="#EA8A1C">
<tr>
<td height=40 colspan=2 bgcolor="#FFDA00"><strong>登录到 Broadband Router:</strong></td>
<tr>
<td id="title">用户名:</td>
<td height=30><input id="text" type=text name=usrname size=12 value="user"></td>
<tr>
<td id="title">口 令:</td>
<td height=30><input id="text" type=password name=passwd size=12 value="user"></td>
<tr>
<td colspan=2 align=center><input type=submit name=login value="提 交"></td>
</table>
</FORM>

<div>
[ <A href="?!=/login.csp&lang=ch" target=_top>中文</A> |
<A href="?!=/login.csp&lang=en" target=_top>English</A> |
<A href="?!=/login.csp&lang=jp" target=_top>日本語</A> ]
</div>
<p style="margin-top: 30px">(来自 http://www.eybuild.com)</p>
</center>
</body>
</html>

Message body has been unpacked.


Good Luck!
mrshelly 2007-04-29
  • 打赏
  • 举报
回复
取数据时,不要发送 gzip 头.
fxs_2008 2007-04-29
  • 打赏
  • 举报
回复
试试楼上两位的方法,成功通知大伙一声
Go_Rush 2007-04-29
  • 打赏
  • 举报
回复
或者试一下这个
$text=gzuncompress($raw_gzip_data);
Go_Rush 2007-04-29
  • 打赏
  • 举报
回复
之所以取到的数据是 gzip格式的,是因为你发送请求的时候

发送了 这个请求头.
Accept-Encoding: gzip, deflate


,你改以下你的代码,去掉 Accept-Encoding: gzip, deflate 这个请求头就可以了
youngpand 2007-04-29
  • 打赏
  • 举报
回复
TO mrshelly(Shelly)
"取数据时,不要发送gzip头"
那应该怎样解码??谢谢
fxs_2008 2007-04-29
  • 打赏
  • 举报
回复
查了一下,gzip表示数据压缩过
可能要解压
adverse 2007-04-28
  • 打赏
  • 举报
回复
php不清楚,帮顶。
Fufay 2007-04-28
  • 打赏
  • 举报
回复

gzuncompress($someData)
Meteorlet 2007-04-28
  • 打赏
  • 举报
回复
string gzdecode ( string $data [, int $length] )
jacklinchen 2007-04-28
  • 打赏
  • 举报
回复
gzip编码? 没见过,帮你顶一下
Re: 《文件备份与压缩命令》 ---------------------------------------内容提要: 1/6)tar   命令:打包备份/解压打包(将文件或目录的压缩或不解压查看查看)2/6)gzip  命令:压缩或解压文件3/6)zip   命令:打包和压缩文件4/6)unzip 命令:解压zip文件5/6)scp   命令:远程文件复制(全量备份)6/6)rsync 命令:文件同步工具(增量备份)  本人在教学和实战过程中发现,即便是有一定运维经验的人,可能已经能够搭建一定复杂度的Linux架构,但是在来来回回的具体操作中,还是体现出CLI(命令界面)功底不够扎实,甚至操作的非常‘拙’、处处露‘怯’。 对一个士兵来说,枪就是他的武器,对于一个程序员来说,各种library(工具库)就是他的武器;而对于Linux运维人员来说,无疑命令行工具CLI(命令界面)就是他们的武器;高手和小白之间的差距往往就体现在对于这些“武器”的掌握和熟练程度上。有时候一个参数就能够解决的事情,小白们可能要写一个复杂的Shell脚本才能搞定,这就是对CLI(命令界面)没有理解参悟透彻导致。 研磨每一个命令就是擦拭手中的作战武器,平时不保养不理解,等到作战的时候,一定不能够将手中的武器发挥到最好,所以我们要平心、静气和专注,甘坐冷板凳一段时间,才能练就一身非凡的内功! 本教程从实战出发,结合当下流行或最新的Linux(v6/7/8 版本)同时演示,将命令行结合到解决企业实战问题中来,体现出教学注重实战的务实精神,希望从事或未来从事运维的同学,能够认真仔细的学完Linux核心命令的整套课程。 本课程系列将逐步推出,看看我教学的进度和您学习的步伐,孰占鳌头! 注:关于教学环境搭建,可以参考本人其它课程系列,本教学中就不再赘述! 《参透 VMware 桌面级虚拟化》 《在虚拟机中安装模版机(包括应用软件等)》 《SecureCRT 连接 GNS3/Linux 的安全精密工具》

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧