WebClient卡死
使用WebClient进行模拟浏览器,但总是出现直接卡死的问题,超时设置了
我扩展了基本的WebClient,下面是 关键代码
protected override WebRequest GetWebRequest(Uri address)
{
InitHeader();
Request = (HttpWebRequest)base.GetWebRequest(address);
Request.MaximumAutomaticRedirections = 1000;
if (Timeout <= 0)
Timeout = 60;
Request.Timeout = Timeout * 1000;
Request.ReadWriteTimeout = Timeout * 1000;
Request.AllowAutoRedirect = AllowAutoRedirect;
Request.CookieContainer = this._cookieContainer;
Request.KeepAlive = true;
Request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
if (address.ToString().StartsWith("https"))
{
Credentials = CredentialCache.DefaultNetworkCredentials;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = callback;
}
return Request;
}
protected override WebResponse GetWebResponse(WebRequest request)
{
Response = (HttpWebResponse)base.GetWebResponse(request);
if (Response != null)
{
this._cookieContainer.Add(Response.Cookies);
}
return Response;
}
new WebClientEx().DownloadString("xxxxx")