Chunked transfer encoding is a data transfer mechanism in version 1.1 of the Hypertext Transfer Protocol (HTTP) in which data is sent in a series of "chunks". It uses the Transfer-Encoding HTTP header in place of the Content-Length header, which the earlier version of the protocol would otherwise require.[1] Because the Content-Length header is not used, the sender does not need to know the length of the content before it starts transmitting a response to the receiver. Senders can begin transmitting dynamically-generated content before knowing the total size of that content.

---from http://en.wikipedia.org

为了避免在动态aspx页面输出动态的字节流的时候,页面自动转为Chunked Transfer Encoding,我们需要设置一下:

Response.AppendHeader("Content-Encoding", "no");

然后根据字节数组的长度自行计算一下Content-Length并显示写入:

Response.AppendHeader("Content-Length", (data.Length).ToString());

就可以避免在客户端编写下载代码的时候,编写代码来判断Chunked Transfer Encoding的结束标记(0\r\n\r\n)了。