Transfer-Encoding: chunked 的含意
Transfer-Encoding: chunked 的含义Transfer-Encoding: chunked 的含义在用firebug查看服务器的请求时,返
Transfer-Encoding: chunked 的含义
Transfer-Encoding: chunked 的含义
在用firebug查看服务器的请求时,返回的header都有Transfer-Encoding: chunked,在做实际应用时,好像也
没有多大关系。
试试用socket连接http服务器,看看数据是如何传输的。
<%??????out.print("helloworld!");??????out.flush();??????out.print("123");??????out.flush();??%>??
输出结果是:
引用
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=8A7461DDA53B4C4DD0E89D73219CB5F8; Path=/
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 10 Nov 2010 07:10:05 GMT
b
helloworld!
3
123
0
其中Transfer-Encoding:chunked表示内容长度在后面介绍,b这个16进制数字就表示长度为11,然后是内容
(helloworld!),然后以\r\n结束,如果有下一段,则一个16进制数字表示长度,直到最后一段没有了,才以0
结束。
不过不用担心,在浏览器里会自动解释分析,不会让你看到b,3,0,就算在firebug里也显示的是helloworld!
123。
如果自己解析,就需要注意了。