I am getting the following exception:
The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF
From this question:
HttpWebRequestError: The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF
I understand that I need to set useUnsafeHeaderParsing to True.
Here is my code:
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
WebResponse myResp = myReq.GetResponse(); //exception is thrown here
useUnsafeHeaderParsing is a property of HttpWebRequestElement class.
How do I integrate it in the above code?
You need to set this is in your web.config, inside <system.net>
section, like this:
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
If, for some reason, you do not want to do it from your config, you could do it from code by prgrammatically setting your config settings. See this page for an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With