Chunked transfer encoding browser experience

对着背影说爱祢 提交于 2019-12-22 01:07:28

问题


Why the output of this simple Perl script >>

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";

...works for Chrome browser and does not for IE10..?


回答1:


You’ve implemented the chunked transfer coding wrong: Each chunk consists of the chunk size in bytes in hexadecimal notation, followed by a CRLF sequence, followed by the chunk data:

   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)

So your code should look like this:

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";


来源:https://stackoverflow.com/questions/17153009/chunked-transfer-encoding-browser-experience

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!