如何解码gzip编码的html? [英] How to decode gzip encoded html?

查看:176
本文介绍了如何解码gzip编码的html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Web服务器获得数据:

I got data from web server:

data := '
HTTP/1.1 200 OK
Content-Encoding: gzip
Vary: Accept-Encoding
Content-type: text/html
Transfer-Encoding: chunked
Server: Apache

3d5
????????????????????????????????????
????????????????????????????????????
????????????????????????????????????
';

数据大小为:3d5(十六进制)
全部存储到TIdBytes变量数据。

The size of data is: 3d5 (in hex) all is stored to TIdBytes variable "data".

如何解码gzip压缩的数据,更改其中的某些内容以及回编码并将长度3d5编辑为新的长度。

How to decode gziped data, change something in it, and encode back and edit the length 3d5 to new.

推荐答案

Transfer-Encoding 响应标头设置为 chunked 。这意味着服务器以块的形式发送主体数据,其中每个块表示其自身的大小,其中0长度的块表示数据的末尾。 3d5 是指第一个块的大小。仅在响应中只有1个数据块时,这才是HTML的完整大小。

The Transfer-Encoding response header is set to chunked. That means the server sends the body data in chunks, where each chunk indicates its own size, where a 0-length chunk indicates the end of the data. The 3d5 refers to the size of the first chunk. That would be the full size of the HTML only if there is just 1 chunk of data in the response.

TIdHTTP 在内部为您处理分块数据。如果已将解块的数据进行gzip压缩,则如果您分配 TIdZLibCompressorBase -,则 TIdHTTP 可以为您解压缩数据派生组件,例如 TIdCompressorZLib ,预先分配到 TIdHTTP.Compressor 属性。

TIdHTTP internally handles chunked data for you. If the de-chunked data has been gzip'ped, TIdHTTP can decompress it for you if you assign a TIdZLibCompressorBase-derived component, such as TIdCompressorZLib, to the TIdHTTP.Compressor property beforehand.

这篇关于如何解码gzip编码的html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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