Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 4 即使在使用useUnsafeHeaderParsing之后,服务器仍犯下协议冲突错误_Asp.net Mvc 4_C# 4.0 - Fatal编程技术网

Asp.net mvc 4 即使在使用useUnsafeHeaderParsing之后,服务器仍犯下协议冲突错误

Asp.net mvc 4 即使在使用useUnsafeHeaderParsing之后,服务器仍犯下协议冲突错误,asp.net-mvc-4,c#-4.0,Asp.net Mvc 4,C# 4.0,我正在尝试从MVC中的外部URL获取XML响应 这是我的代码: Uri uri = new Uri("http://101.10.3.111:8600/out"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.ContentType = "application/x-www-form-

我正在尝试从MVC中的外部URL获取XML响应

这是我的代码:

        Uri uri = new Uri("http://101.10.3.111:8600/out");
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
        request.Method = "GET";
        request.ContentType = "application/x-www-form-urlencoded";
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";

        request.ServicePoint.Expect100Continue = false;
        request.KeepAlive = false;

        try
        {
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode == HttpStatusCode.OK)
            {
                // as an xml: deserialise into your own object or parse as you wish
                var responseXml = XDocument.Load(response.GetResponseStream());
                Console.WriteLine(responseXml.ToString());
            }
        }
        catch (Exception ex)
        {

        }
它给出了这个错误:

{"The server committed a protocol violation. Section=ResponseStatusLine"}
如果我将其添加到web.config:

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

另外,如果我调用copy\paste将url粘贴到浏览器中,它会给我输出文件。

以下帖子建议,如果useUnsafeHeaderParsing修复程序对您无效,您应该尝试更改KeepAlive设置:我在代码中做了更改:request.KeepAlive=false;我错过了——抱歉。
{"The underlying connection was closed: The connection was closed unexpectedly."}