HTTP Chunk学习记录

HTTP chunked

chunk是http协议新增的一种分块传输编码格式,用于服务传输那些非静态页面(大小固定)。此类页面旺旺需要动态响应,即一遍产生数据,一遍发送给客户端,服务器并不知道页面内容的大小。

使用格式

  • 消息头部:Transfer-Encoding: chunked
  • 若干chunk:第一部分是该chunk的长度,第二部分就是指定长度的内容,每个部分用CRLF隔开,最后以一个长度为0的chunk结束,即"0\r\n\r\n"。
    1. 格式:[chunk size][\r\n][chunk data][\r\n][chunk size][\r\n][chunk data][\r\n][chunk size = 0][\r\n][\r\n]
    2. chunk size是以十六进制的ASCII码表示,即对于31 34 对应的ASCII值为49 52,即1和4,对应十进制为20

举例:

HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked

25 => (37个字符,包含有"\r\n")
This is the data in the first chunk

1C => (28个字符,包含有"\r\n")
and this is the second one

3
con

8
sequence

0 => ("0\r\n\r\n")

以上即为:

This is the data in the first chunk
and this is the second one
consequence

参考:[添加链接描述]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值