Partager via


HttpWebRequest.GetResponse() gives "HTTP protocol violation" error after .net frameworks service packs

This blog is valid for users of .Net frameworks 1.0 SP3 and .Net frameworks 1.1 SP1

The error is really because server is sending response with bad header format, which violates the http protocol specifications. These changes had been made to disallow bad headers. Bad http header could cause security vulnerability based on response-splitting and other attacks based on misinterpreting HTTP streams. 

However if your application still need to deal with such responses, you could roll back to old bahavior of relaxed header parsing. You need to use following app.config file.

<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true"/>
</settings>
</system.net>
</configuration>

This posting is provided "AS IS" with no warranties, and confers no rights

Comments

  • Anonymous
    November 09, 2004
    I get this ("HTTP protocol violation") when communicating from .NET to the embedded HTTP server in my wireless access point, a Buffalo Airstation WLAR-L11-G.


    I built the app to automate the configuration of the thing. After a while, the router gets confused and it stops handing out DHCP addresses. With the utility, I can reset the router, via the wired connection, from a scheduled task.


    Anyway, the airstation is HTTP 1.0, as you said. I did not know about the config setting. I just try...catch.. the GetResponse() and check it to see if it is the expected protocol violation, and swallow the exception if it is.

  • Anonymous
    June 30, 2009
    The comment has been removed
  • Anonymous
    August 11, 2009
    即ハメセレブは完全無料でご利用できる出会いコミュニティです。今までにない実績で、あなたの希望に合った人をお探しします。毎月考えられない豪華なイベントを開催しているので出会いを保障します