我想一个客户端的数据下载到我的本地计算机(编程)和他们的网络服务器是非常,这是造成我的 Web客户端
对象超时很慢。
I am trying to download a client's data to my local machine (programatically) and their webserver is very, very slow which is causing a timeout in my WebClient
object.
下面是我的code:
WebClient webClient = new WebClient();
webClient.Encoding = Encoding.UTF8;
webClient.DownloadFile(downloadUrl, downloadFile);
有没有一种方法来设置这个对象上的无限超时?或者,如果没有谁能帮我用一个例子上的另一种方法来做到这一点?
Is there a way to set an infinite timeout on this object? Or if not can anyone help me with an example on an alternate way to do this?
该网址工作正常,在浏览器 - 它只是需要大约3分钟以示
The URL works fine in a browser - it just takes about 3 minutes to show.
您可以延长超时:继承了原WebClient类,并重写的WebRequest吸气设置自己的超时时间,就像下面的例子。 MyWebClient是一个私有类在我的情况
You can extend the timeout: inherit the original WebClient class and override the webrequest getter to set your own timeout, like in the following example. MyWebClient was a private class in my case
private class MyWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest w = base.GetWebRequest(uri);
w.Timeout = 20 * 60 * 1000;
return w;
}
}