private void button1_Click(object sender, EventArgs e)
{ HttpWebRequest wrt = (HttpWebRequest)WebRequest.Create("http://www.google.cn");
wrt.Accept = "Accept: application/x-shockwave-flash, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*";
wrt.Headers.Add("Accept-Language", "zh-cn");
wrt.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
wrt.KeepAlive = true;
HttpWebResponse response = (HttpWebResponse)wrt.GetResponse(); Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
string html = sr.ReadToEnd(); textBox1.Text = html;
}代码如上,怎么设置才可以程序点击运行就立即获取网页而不停顿呢?
{ HttpWebRequest wrt = (HttpWebRequest)WebRequest.Create("http://www.google.cn");
wrt.Accept = "Accept: application/x-shockwave-flash, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*";
wrt.Headers.Add("Accept-Language", "zh-cn");
wrt.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
wrt.KeepAlive = true;
HttpWebResponse response = (HttpWebResponse)wrt.GetResponse(); Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
string html = sr.ReadToEnd(); textBox1.Text = html;
}代码如上,怎么设置才可以程序点击运行就立即获取网页而不停顿呢?
你好.你的回答让我有些汗...request不是webbrowser呀..同ie无关.更不关病毒的事...应该是dns什么的事.但我不知道应该怎么设置
或者说,你用IE或者别的软件会不会遇到同样的问题。
别的机器呢?
确认你的问题出现在你的程序,或者 inet 库,或者 socket 库,或者网络。
你好.谢谢你的回复,但确实不关ie或其他软件的事.不信你自己运行一下上面的代码就清楚了.我试过不下五个机都是这个样子.IE没延时...tcpclient或socket直接编写的也是没有延时...唯独这个request就是程序一次建立连接时总要停滞30秒(现象是右下角的网络状态的那个小电脑图标:点运行后来回亮两下,然后30秒内无数据传输,30秒后才开始获取网页)