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