Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Setting timeout property for System.Net.WebClient Class

0.00/5 (No votes)
20 Jun 2011CPOL 25.3K  
You can also use the System.Net.HttpWebRequest implementation of System.Net.WebRequest. It comes packaged with a timeout property - http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx.It would be a simple call to the object:...using System.Net;...HttpWebRequest...

You can also use the System.Net.HttpWebRequest implementation of System.Net.WebRequest. It comes packaged with a timeout property - http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx.


It would be a simple call to the object:


C#
...
using System.Net;

...

HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(new Uri("www.microsoft.com"));
webRequest.Timeout = 10000; // setting timeout value to 10 secs

HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

// you may now use a stream reader to read the response stream

...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)