HttpWebRequest开始超时

时间:2013-12-05 08:27:34

标签: c# timeout httpwebrequest

昨天我能够向HTTP设备发送GET个请求:

string urlString = "http://192.168.1.100/........."
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(urlString);
request.Timeout = 1000;
request.Credentials = new NetworkCredential("the_login_name", "the_password");
request.GetResponse().Close();

但今天这些请求超时,好像设备的主机已关闭,虽然我可以从浏览器手动发送这些请求,但设备会立即响应。

HttpWebRequest可能会发生什么?

1 个答案:

答案 0 :(得分:2)

request.ServicePoint.ConnectionLeaseTimeout = 5000;
request.ServicePoint.MaxIdleTime = 5000;