为什么这个简单的 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..?
为什么这个简单的 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";