300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > HTTP返回内容前面出现一个多出来的数字 Transfer-Encoding: chunked

HTTP返回内容前面出现一个多出来的数字 Transfer-Encoding: chunked

时间:2018-10-11 12:12:13

相关推荐

HTTP返回内容前面出现一个多出来的数字 Transfer-Encoding: chunked

我们用测试工具例如postman测试post或者get返回内容是很正常的。但是从编程调试可以看到变量的内容是这样的:

postman:

HTTP/1.1 200 OK

Date: Fri, 09 Sep 02:00:23 GMT

Server: Apache

Upgrade: h2,h2c

Connection: Upgrade

Transfer-Encoding: chunked

Content-Type: text/plain

length is 4the content length is 4POST DATA: _AE_

c++调试:

HTTP/1.1 200 OK

Date: Fri, 09 Sep 02:32:51 GMT

Server: Apache

Upgrade: h2,h2c

Connection: Upgrade, Keep-Alive

Keep-Alive: timeout=500, max=100

Transfer-Encoding: chunked

Content-Type: text/plain

31

length is 4the content length is 4POST DATA: _AE_

之前没有弄懂这个31的意义,后面好不容易找到一段解答:

这个是http协议中的chunked分组,对于长度较长无法一下确定内容长度的网页,服务器就会将网页内容分块发送,然后在本地重新解码、组装。

基本格式是[Chunk大小][回车][Chunk数据体][回车][Chunk大小][回车][Chunk数据体][回车][0][回车]

根据这个格式,用c/c++解码是比较简单的,不过需要注意的是chunk大小是16进制的ascii形式,这个需要进行转换,详细的介绍baidu或google “http协议 chunked”

如上的31则是3*16+1=49个字节。数一数后面的内容果然是。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。