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);
时间: 2024-11-01 16:01:51