“The underlying connection was closed: The server committed an HTTP protocol violation.
Error reading URL: The underlying connection was closed: The server committed an HTTP protocol violation.
Please try to validate this feed. If this feed validates as correct RSS, you can send an error report. “
If you use an RSS feeds agregator like SharpReader, SauceReader or FeedReader, this error might sound familiar to you. Here is an explanation on how to prevent this…
The issue
The HTTP header keys for example shoud specifically not include any spaces in their names. However, some web servers do not fully respect standards they’re meant to.
Applications running on the Dotnet framework and making heavy use of http requests usually use the “httpWebRequest” class, which encapsulates everything a web oriented developer could dream of. With all the recently issues related to security, the “httpWebRequest” class provides a self protection mechanism preventing it to accept HTTP answers which not fully qualify to the specifications.
The common case is having a space in the ‘content-length’ header key. The server actually returns a “content length” key, which, assuming no spaces are allowed, is considered as an attack vector (HTTP response split attack), thus, triggering a “HTTP protocol violation error” exception.
The workaround
It is possible since the 1.1 SP 1 DotNet version (UPDATE: see comments for instructions prior to version 1.1, credits to Krys Oye) to disable this error check. (Un)Fortunately, DotNet allows you to modify some parameters directly through a simple text configuration file, thus not requiring the user to have some strong developer skills.
I tested this on SharpReader and it immediatly unlocked all the ‘red’ feeds I had.
1. Create a file and name it like ‘yourapplication.extension.config‘. If for example you’re using SharpReader, then create a file named ‘SharpReader.exe.config‘.
2. Open this file with a notepad or any text-based editor and paste the following text in it:
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
*: Be carefull: if you already see that file in the folder, edit it, and only insert the missing sections in it. Do not try to reproduce a second ‘configuration’ area for example as it will invalidate that configuration file.
3. Save it, then restart your application. That should work now.
Thanks to…
This workaround was found on Gille’s weblog, thanks to him: I can keep my favourite SharpReader