Welcome to MSDN Blogs Sign in | Join | Help

adarsh's blog

Adarsh Khare works at Microsoft. Everything here, though, is his personal opinion and is not read or approved by Microsoft before it is posted. No warranties or other guarantees will be offered as to the quality of the opinions or anything else offered here.
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

Posted: Monday, November 08, 2004 12:44 PM by adarshk

Comments

DinoCh said:

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.
# November 9, 2004 8:47 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker