WebClient类是重写了WebRequest方法得到的DownloadFile,DownloadData
WebRequest类本来的Timeout属性。
WebClient类集成了WebRequest类,那么,当我运用WebClient类的时候,如果不做任何设置(timeout),可以认为WebClient的默认timeout就是WebRequest类的默认timeout
public class WebCS : WebClient
{
//重写超时时间
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
request.Timeout = 1000 * 300;//单位为毫秒
request.ReadWriteTimeout = 1000 * 300;//
return request;
}
}