问题
If you are using it for simple purposes, WebClient is enough. Absence of Timeout you can inherit it and override it's GetWebRequest method easily:
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
request.Timeout = Timeout;
return request;
}
If you are using it multithreaded way, you have to set MaxConnection by code or app.config: Improving performance of multithreaded HttpWebRequests in .NET
You can parallelize it easily also: Best practics for parallelize web crawler in .net 4.0
Maybe Microsoft created new HttpClient class for implemantation problems of WebClient (HttpWebRequest)
But it does not have Proxy,Gzip support.
For WebClient:
Setting up Timeout still useless in multithreaded implemantation!
Concurrency Limit on HttpWebRequest
So the question:
I need FastWebClient with proxy,timeout(working one),gzip support. I will use it with multiple proxies, so I definetely need multiple FastWebClient.
Or Helper:
FastWebHelper.DownloadString (string url,WebProxy proxy,int timeout)
Any idea ?
回答1:
Sure. WebClient.DownloadStringAsync Method You would still need to create 1 WebClient instance per connection/request, as it's not stateless.
来源:https://stackoverflow.com/questions/12353334/timeout-supported-multithreaded-web-request