Bytes to be written to the stream exceed the Content-Length bytes size specified 解决方法

context.Response.ContentType = encode;               
using (StreamWriter writer = new StreamWriter(context.Response.OutputStream, UTF8))
    {
          writer.Write(str);
    }

上面代码常会报错:

 Bytes to be written to the stream exceed the Content-Length bytes size specified 

解决方法:

添加: context.Response.ContentLength64 = string.IsNullOrWhiteSpace(str) ? 0 : UTF8.GetByteCount(str); 

原文地址:https://www.cnblogs.com/94cool/p/4024809.html