Substitute for WebClient to Prevent Timeouts?

You could use a WebClient derived class for this, which just adds the timeout you want for each fetch: public class TimeoutWebClient : WebClient { protected override WebRequest GetWebRequest(Uri address) { HttpWebRequest request = (HttpWebRequest)base. GetWebRequest(address); request. Timeout = 60000; //1 minute timeout return request; } } If you use TimeoutWebClient instead of WebClient now, you get the timeout behavior that you want.

If the custom headers you need are the same for each request, you could add those here as well and your calling code remains very clean.

– Sonic42 Oct 23 at 18:36 @Sonic42: Yes that's correct – BrokenGlass Oct 23 at 19:11.

XmlDocument xmlDoc = new XmlDocument(); HttpWebRequest request = new (HttpWebRequest)WebRequest. Create(/*URL*/); request. Headers = new WebHeaderCollection(); // fill in request.Headers... // The response is presented as a stream.

Wrap it in a StreamReader that // xmlDoc. LoadXml can accept. XmlDoc.

LoadXml(new StreamReader(request.GetResponse(). GetResponseStream()).

You could just catch the exception, then reissue the request. You might want to put some other logic in here to abort after a certain number of failed attempts. Bool continue; do{ continue = false; try { string data = client.

DownloadString(/*URL*/); } catch (WebException e) { continue = true; } } while(continue).

– L. B Oct 23 at 18:35 Doesn't that create an infinite loop if the request is successful? – Sonic42 Oct 23 at 18:37 @L.

B - He said it usually responds fast, and only occasionally times out. It may be that the server aborts and never completes the request, so a long timeout will just wait until it times out no matter how long. – Mystere Man Oct 23 at 18:38 @Sonic42 - Good catch, fixed.

– Mystere Man Oct 23 at 18:40 @MystereMan But your code doesn't show how to set a short timeout, So that any new trial can be done quickly. – L. B Oct 23 at 19:14.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions