Timeout supported Multithreaded Web Request

孤人 提交于 2019-12-25 01:19:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!