Search code examples
c#.netapp-config.net-framework-version

The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF


My App.config file

<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
  <system.net>
    <settings>
      <httpWebRequest useUnsafeHeaderParsing="true" />
    </settings>
  </system.net>
</configuration>

I was facing the below error when I was trying to download some .pdf file from a url.

The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF

After extensive research, most of the suggestions are to add useUnsafeHeaderParsing="true" in config file, but unfortunately it was already present in my config file.

But I realized that, all the examples in suggested solutions are not having this particular line

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>

So I went ahead and removed and tried to download the .pdf file

<?xml version="1.0"?>
<configuration>
  <system.net>
    <settings>
      <httpWebRequest useUnsafeHeaderParsing="true" />
    </settings>
  </system.net>
</configuration>

and it worked. My application is built using .Net Framework 4

What I am trying to understand is there any impact of removing this line, or it can fixed in some other way ?


Solution

  • In my experience, removing the line, wouldn't not "break" anything. That line just target the .NET framework 4.0 directly in your application.

    https://www.codeproject.com/Articles/886256/NET-versioning-and-multi-targeting-on-Csharp-appli

    Here is a good and lengthy code project file I came across last year December when converting some of my projects and cleaning out some "useless" code from files