小编pat*_*ice的帖子

使用Google Chrome和HTTPListener获取ProtocolViolationException

我开发了一个管理工具,我使用一个简单的HTTPListener来返回HTML页面.一切都适用于IEFF但我在使用谷歌浏览器时遇到了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做或不做什么来产生此错误?

谢谢

.net c# browser httplistener

5
推荐指数
1
解决办法
1464
查看次数

标签 统计

.net ×1

browser ×1

c# ×1

httplistener ×1