您的位置:首页 > 运维架构 > 网站架构

获得网站页面源代码

2006-08-24 09:46 218 查看
1protected void Button1_Click(object sender, EventArgs e)
2 {
3 WebProxy wp = (WebProxy)GlobalProxySelection.Select; //获取机器默认的proxy服务器变量
4 wp.Credentials = CredentialCache.DefaultCredentials; //将机器上默认的信任传入刚才指定的proxy服务器变量
5
6
7 HttpWebRequest myRq = (HttpWebRequest)HttpWebRequest.Create("http://www.baidu.com");
8
9 myRq.Proxy = wp;
10 myRq.KeepAlive = true;
11 myRq.Timeout = 10000;
12 myRq.Method = "GET";
13
14 HttpWebResponse myRp = null;
15 StreamReader sr = null;
16 Stream myStr = null;
17 System.Text.StringBuilder sb = new System.Text.StringBuilder();
18
19 myRp = (HttpWebResponse)myRq.GetResponse();
20 myStr = myRp.GetResponseStream();
21 sr = new StreamReader(myStr, System.Text.Encoding.Default);
22 while (sr.Peek() != -1)
23 {
24 sb.Append(sr.ReadToEnd());
25 }
26 Response.Write(sb);
27
28 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: