【发布时间】:2010-12-14 09:26:26
【问题描述】:
我有一些代码可以发送一个简单的 xml 网络请求。它是从 Windows 服务调用的。有时服务开始抛出异常(System.Net.WebException:操作已超时)并且重新启动服务可以解决问题。代码如下:
public bool PerformXmlRequest(string xml)
{
var httpRequest = (HttpWebRequest)WebRequest.Create(_url);
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml";
using (var xmlWriter = new StreamWriter(httpRequest.GetRequestStream(), Encoding.UTF8))
{
xmlWriter.WriteLine(xml);
}
using (var httpResponse = (HttpWebResponse)httpRequest.GetResponse())
{
return httpResponse.StatusDescription == "OK";
}
}
是否有任何明显的错误可能导致此问题?
【问题讨论】:
标签: memory-leaks httpwebrequest timeout system.net.webexception