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

前端 未结 2 1518
野趣味
野趣味 2021-01-01 09:04

I am trying to use a WebClient / HttpWebRequest to download some data from a server. I use the following code to do so:

WebClient client = new WebClient();
c         


        
相关标签:
2条回答
  • 2021-01-01 09:09

    Your problem might not require any app.config changes (and in my case, this configuration change made no difference). I would try modifying your Accept: header, as suggested in this link.

    In my case, I create an HttpWebRequest directly, so my solution was to add the following:

    request.Accept = "text/html, application/xhtml+xml, */*"
    
    0 讨论(0)
  • 2021-01-01 09:31

    First, adding an app.config file is just as easy as adding any other file, How to: Add an Application Configuration File to a C# Project

    Then you just have to add that code snippet above to that new app.config.

    Another way of setting that property via code, avoiding the need for an app.config is shown here or here.

    0 讨论(0)
提交回复
热议问题