5
我开发了一个管理工具,我使用简单的HTTPListener来返回HTML页面。一切正常与IE和FF但我得到ProtocolViolationException当使用Google Chrome。使用Google Chrome和HTTPListener获取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();
异常
字节将被写入到该流超过内容长度的字节指定大小。
从管线
context.Response.OutputStream.Write(缓冲液,0,buffer.Length)抛出;
什么是Chrome做或不做这个错误?
感谢
为了记录,您必须至少在接收到HEAD请求时关闭响应流,否则您会一直卡住。 – pierrecouzy 2012-04-05 17:57:14