处理HTTP ContentEncoding“deflate” [英] Handling HTTP ContentEncoding "deflate"

查看:616
本文介绍了处理HTTP ContentEncoding“deflate”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应该使用哪种 InputStream 类型来处理将HTTP 内容编码设置为 deflate 的URLConnection流?

What InputStream type should be used to handle URLConnection streams that have HTTP Content-Encoding set to deflate?

对于gzip或zip的内容编码,我使用GZIPInputStream,没问题。

For a Content-Encoding of gzip or zip I use a GZIPInputStream, no problem.

对于deflate的内容编码我尝试使用 InflaterInputStream DeflaterInputStream ,但我得到了

For a Content-Encoding of "deflate" I have tried using InflaterInputStream and DeflaterInputStream but I get


java.util。 zip.ZipException:unknown
压缩方法
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:147)

java.util.zip.ZipException: unknown compression method at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:147)

我的理解是deflate编码指的是 Zlib 压缩,并且根据文档这应该由InflaterInputStream处理。

My understanding is that "deflate" encoding refers to Zlib compression, and according to the docs this should be handled by InflaterInputStream.

推荐答案

在HTTP / 1.1中,内容编码:deflate 实际上是指由 RFC 1951 定义的DEFLATE压缩算法,包含在zlib数据格式,由 RFC 1950 定义。

In HTTP/1.1, Content-encoding: deflate actually refers to the DEFLATE compression algorithm, as defined by RFC 1951, wrapped in the zlib data format, as defined by RFC 1950.

然而,一些供应商只是实现了RFC 1951定义的DEFLATE算法,完全忽略了RFC 1950(没有zlib头文件)。

However some vendors just implement the DEFLATE algorithm as defined RFC 1951, completely ignoring RFC 1950 (no zlib headers).

其他人已被点击同一问题:

Others have been hit by the same issue:

  • http://www.mail-archive.com/www-talk@w3.org/msg01000.html
  • Internet Explorer 8 + Deflate

为了解决这个问题,尝试实例化 InflaterInputStream 传递 Inflater 用t创建的他 nowrap 参数设置为 true

In order to work around this, try to instantiate the InflaterInputStream passing an Inflater that was created with the nowrap parameter set to true:

in = new InflaterInputStream(conn.getInputStream()), new Inflater(true));

这篇关于处理HTTP ContentEncoding“deflate”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆