The server committed an HTTP protocol violation
Thanks to Communication WEB for pointing out a fix to this error which started springing up after .NET Framework 1.1 SP1 was released. To enhance security, this error will be raised on fetching from a web site if the server’s HTTP headers obey certain rules e.g. there cannot be a space in the header name. The problem is that some websites do not conform.
To avoid errors on trying to fetch from these sites, you can add the following to your web.config file:
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
If you have a batch file or console application that is affected, you can resolve the issue by making a file called yourapp.exe.config (where yourapp is the name of your executable) containing the above code. You may need to precede this with the line:
<?xml version=”1.0″ encoding=”utf-8″ ?>



February 27th, 2005 at 5:16 am
Hi Janine,
When I use httpwebrequest I met the same problem, and I am very exciting when I see you solution. But when I try it, I met another problem. I use :
HttpWebRequest req =(HttpWebRequest)WebRequest.Create(sURL);
,and I got an exception like :
An unhandled exception of type ‘System.Configuration.ConfigurationException’ occurred in system.dll
Additional information: Unrecognized attribute ‘useUnsafeHeaderParsing’
would you please tell me how to solve it?
thanks a lot!
Alan
March 21st, 2005 at 10:05 pm
Hi Janine,
I think that alan’s problem is probobly because he’s using a version of .NET prior to 1.1 sp1? I just mirrored a website accross two virtually identical webservers, and one threw the error that alan mentioned.
Inidentally, are you involved with Developers.ie?. They’re a new focus group for .NET developers in Ireland (well Dublin).
Keep in touch.
Fiach
ps: also, have a look at the URL, you might be interested in my book
March 21st, 2005 at 10:18 pm
hi fiach,
yep i’d say that’s alan’s problem alright… sorry alan, i forgot all about you!!
i know i encountered this error in exactly the same way…
i was scraping a website and it worked remotely and then stopped working, but never stopped working locally, and still worked remotely using php (which discounted ip issues). the reason it had stopped working was because the framework change had been installed on the remote server.
when i implemented the fix outlined here, it worked fine on the remote server but caused alan’s exception locally.
i have recently been keeping an eye on developers.ie fiach (i’d even heard about your book of late
)… it’s just that being a bit of a busy newbie, i haven’t had the time (or courage!) to get involved yet 
September 12th, 2006 at 9:14 pm
I searched on Google and you are the first link in the results.
I tried your solution and it worked.
Just wanted to say thank you!
December 11th, 2007 at 2:18 am
This seems to be a pretty well documented solution. I have encountered this error posting XML requests. The fix works when I am calling from a .aspx application, but the fix does not work when I am calling from a win32 app? Any ideas?
December 12th, 2007 at 12:00 am
Sorry Greg - I only have knowledge of web apps so I can’t help you with your desktop bug, but hopefully Google will have the answer if nobody posts back here. Good luck