Asp.net mvc 4 即使在使用useUnsafeHeaderParsing之后,服务器仍犯下协议冲突错误
我正在尝试从MVC中的外部URL获取XML响应 这是我的代码: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-
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."}