1

I am using this code for read content from URL:

        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(urlAddress);
        req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)";
        using (var resp = req.GetResponse())
        {
            var html = new StreamReader(resp.GetResponseStream()).ReadToEnd();
            return html;
        }

+ In app.config I have:

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

In my pc - where I code the program it work nice, but when I make exe file and try to run on my webserver I am getting error:

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

How can I fix this error.

Thank you for your help!

  • Possible duplicate of [The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF, In WinForms?](http://stackoverflow.com/questions/16759349/the-server-committed-a-protocol-violation-section-responseheader-detail-cr-must) – Orkhan Alikhanov Sep 05 '16 at 20:40
  • Poosible duplicate: http://stackoverflow.com/questions/16759349/the-server-committed-a-protocol-violation-section-responseheader-detail-cr-must – Jaime Sep 05 '16 at 20:41
  • None of the above links helped even I have the same problem here https://stackoverflow.com/questions/46469956/file-is-downloading-through-visual-studio-but-not-through-exe#46469956 – Pரதீப் Oct 03 '17 at 12:29

1 Answers1

0

USE This

if (res.Headers.AllKeys.Contains("Vary"))
    {
        res.Headers["Vary"] = "Accept";
    }
    else
    {
        res.Headers.Add("Vary", "Accept");
    }
Arun
  • 410
  • 4
  • 8