我开发了一个管理工具,我使用一个简单的HTTPListener来返回HTML页面.一切都适用于IE和FF但我在使用谷歌浏览器时遇到了ProtocolViolationException.
这是产生错误的简化代码(从listener.BeginGetContext引发):
byte[] buffer = System.Text.Encoding.UTF8.GetBytes("<html><body>response sent!</body></html>");
context.Response.ContentLength64 = buffer.Length;
context.Response.OutputStream.Write(buffer, 0, buffer.Length); //<-- crashes here
context.Response.OutputStream.Close();
context.Response.Close();
Run Code Online (Sandbox Code Playgroud)
例外
要写入流的字节数超过指定的Content-Length字节大小.
被抛出线
context.Response.OutputStream.Write(buffer,0,buffer.Length);
Chrome做或不做什么来产生此错误?
谢谢