下载网页源码时,如何控制下载的时间超时5秒停止下载
如题:下面为下载网页源代码,求朋友如何更改
private string DownHtml(string url, int IntEncoding)
{
string temphtml = " ";
if (IntEncoding==1)
{
WebClient webc = new WebClient();
webc.Credentials = CredentialCache.DefaultCredentials;
Byte[] pageData = webc.DownloadData(url);
temphtml= Encoding.Default.GetString(pageData);
if (temphtml.ToLower().Contains( "charset=utf-8 ")==true){
temphtml= Encoding.UTF8.GetString(pageData);
}
return temphtml;
}
else
{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1) Web-Sniffer/1.0.24 ";
System.Net.WebResponse response = request.GetResponse();
System.IO.Stream resStream = response.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(resStream, System.Text.Encoding.Default);
&n