Handling HTTP ContentEncoding “deflate”

后端 未结 2 1266
失恋的感觉
失恋的感觉 2020-12-11 15:29

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

2条回答
  •  再見小時候
    2020-12-11 16:21

    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.

    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

    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));
    

提交回复
热议问题