急!!!请教高手,使用GZIPInputStream读取错误!
使用GZIPInputStream读取网页,不定时的报以下错误:
java.io.IOException: Not in GZIP format
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:137)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
相关代码如下(使用httpclient下载的页面):
public String getContent(InputStream is, String charset,String url) throws
IOException {
ByteArrayBuffer bab = null;
GZIPInputStream gzipInputStream = null;
BufferedInputStream bfin = null;
String content = "";
try {
bab = new ByteArrayBuffer(4096);
gzipInputStream = new GZIPInputStream(is);
int l;
byte[] tmp = new byte[4096];
while ((l = gzipInputStream.read(tmp)) != -1) {
bab.append(tmp, 0, l);
}
content=new String(bab.toByteArray(),charset);
} catch (IOException ioe) {
...
请教高手是否遇到过类似问题,有没有好的解决办法?
------解决方案--------------------
Not in GZIP format
你读网页的工具是什么阿。
你要分析的网页本身是gzip还是HTTP传输过程中使用了gzip?