Life & Technology

Handful lessons in different areas of technology and life in general.

Tag Archives: ServerProtocol

QuickFix: Server Committed a Protocol Violation Error in .NET

While testing the Hacker News website, I encountered a WebException error which is my first time encountering this kind of message:

The server committed a protocol violation. Section=ResponseStatusLine

I thought this is caused by HAP but I was wrong, a quick MSDN search says that this error occurred because the server response is not a valid HTTP response and has a WebExceptionStatus of ServerProtocolViolation.

If you don’t own the server, chances are you never get to fix the problem on the server itself but Microsoft provided a HttpWebRequestElement property that will ignore validation errors that will occur during parsing:

  1. <>
  2. <settings>
  3. <httpWebRequest useUnsafeHeaderParsing=”true”/>
  4. </settings>
  5. </>

With this setting in place inside your web.config file, the error disappear and HTTP response will be displayed.