通过文件流输出的下载功能遇到的诡异问题
通过文件流输出下载附件,内网下载没有问题,但外网访问下载时,前几次没有问题,多点几次就出现:502 Bad Gateway The server returned an invalid or incomplete response之前我以为是下载大文件时,输出来不及响应造成的,但我改了代码,大文件分段输出了,每段只有10字节,但还是有问题。好奇怪啊!
asp.net asp .net c# --------------------编程问答-------------------- 问题解决了,居然是 Response.AddHeader("Content-Length ", contents.Length.ToString());
iStream = new MemoryStream(d.Content);
long dataToRead = iStream.Length;
// Read the bytes.
while (dataToRead > 0)
{
// Verify that the client is connected.
if (Response.IsClientConnected)
{
// Read the data in buffer.
int length = iStream.Read(buffer, 0, 100);
// Write the data to the current output stream.
Response.OutputStream.Write(buffer, 0, length);
// Flush the data to the HTML output.
Response.Flush();
buffer = new Byte[100];
dataToRead = dataToRead - length;
}
else
{
//prevent infinite loop if user disconnects
dataToRead = -1;
}
}
中 "Content-Length " 多了空格,但是为什么内网就没问题 外网有问题呢???? --------------------编程问答--------------------
支持 学习。 --------------------编程问答-------------------- 除
补充:.NET技术 , ASP.NET