Getting ProtocolViolationException with Google Chrome and HTTPListener

I developed an administrative tool in which I use a simple HTTPListener to return HTML pages. Everything works well with IE and FF , but I get a ProtocolViolationException when using Google Chrome .

This is simplified code (raised from listener.BeginGetContext) that causes an error:

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();

An exception

The bytes to be written to the stream exceed the specified byte size of the content length.

thrown out of line

  context.Response.OutputStream.Write (buffer, 0, buffer.Length);

What is Chrome doing or not doing to create this error?

thank

+5
1

, ( Chrome) . , , , - OutputStream HEAD. ContentLength64 0, - , .

+5

All Articles