我基于HttpListener编写Web服务器代码,但经常出现如下异常:
“System.Net.ProtocolViolationException
context.Response.Output = System.Text.Encoding.UTF8.GetBytes("xxx"); if (context.Response.Output != null && context.Response.Output.Length > 0) { context.Response.ContentLength64 = context.Response.Output.Length; using (var stream = context.Response.OutputStream) { stream.Write(context.Response.Output, 0, context.Response.Output.Length); } }
这个异常并非每次请求都会发生。 有谁能告诉我如何修复它。谢谢!