Im trying to get XML reposnce from External URL in MVC.
This is my Code :
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)
{
}
and it gives this error :
{"The server committed a protocol violation. Section=ResponseStatusLine"}
if i add this to web.config :
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true"/>
</settings>
</system.net>
errors changed to this :
{"The underlying connection was closed: The connection was closed unexpectedly."}
Also if i call (copy\paste) the url into Browser it gives me output file.