分块传输编码浏览器体验

为什么输出这个简单的Perl脚本>>

print "Content-type: text/plain\n"; print "Transfer-Encoding: chunked\n\n"; print "11\n\n"; print "0123456789ABCDEF\n"; print "11\n\n"; print "0123456789ABCDEF\n"; print "0\n\n"; 

…适用于Chrome浏览器,不适用于IE10 ..?

您已经实现了分块传输编码错误:每个块包含以十六进制表示的块大小(以字节为单位),接着是CRLF序列,接着是块数据:

  chunk = chunk-size [ chunk-extension ] CRLF chunk-data CRLF chunk-size = 1*HEX last-chunk = 1*("0") [ chunk-extension ] CRLF chunk-data = chunk-size(OCTET) 

所以你的代码应该是这样的:

 print "Content-type: text/plain\r\n"; print "Transfer-Encoding: chunked\r\n"; print "\r\n"; # first chunk print "10\r\n"; print "0123456789ABCDEF\r\n"; # second chunk print "10\r\n"; print "0123456789ABCDEF\r\n"; # last chunk print "0\r\n"; print "\r\n";