Sometimes you just need a simple WebClient to get back the results from an HTTP Post, but you need to set the timeout, this is how to do that.
public class TimeoutWebClient : WebClient { public int Timeout { get; set; } public TimeoutWebClient() { Timeout = 60000; } public TimeoutWebClient(int timeout) { Timeout = timeout; } protected override WebRequest GetWebRequest(Uri address) { WebRequest request = base.GetWebRequest(address); request.Timeout = Timeout; return request; } }
and call like
TimeoutWebClient client = new TimeoutWebClient { Timeout = 5000 }; var htmlText = client.DownloadString(url);
No comments:
Post a Comment