【问题标题】:System.Net.WebExeption CR must be followed by LFSystem.Net.WebExeption CR 后面必须跟 LF
【发布时间】:2023-03-05 06:12:01
【问题描述】:

我正在使用此代码从 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;
        }

+ 在 app.config 我有:

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

在我的电脑中——我在其中编写程序运行良好,但是当我制作 exe 文件并尝试在我的网络服务器上运行时出现错误:

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

我该如何解决这个错误。

感谢您的帮助!

【问题讨论】:

标签: c# web httpresponse


【解决方案1】:

使用这个

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2011-03-07
    • 1970-01-01
    • 2016-05-09
    • 2019-03-14
    相关资源
    最近更新 更多