C#: Handling WebClient "protocol violation"

Looks like the easiest way is including a .config file with your app containing the following:

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

However it's also possible to do it within the code but it seems a little messy:

http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/ff098248-551c-4da9-8ba5-358a9f8ccc57

Also note that the MSDN definition of that property is

Setting this property ignores validation errors that occur during HTTP parsing.

http://msdn.microsoft.com/en-us/library/system.net.configuration.httpwebrequestelement.useunsafeheaderparsing.aspx

So I'd say it's fairly safe to use, although it does mention to only use it for backwards compatibility.

Tags:

C#