65.9K
CodeProject is changing. Read more.
Home

Setting timeout property for System.Net.WebClient Class

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Jun 20, 2011

CPOL
viewsIcon

25424

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:

...
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

...