获得网站页面源代码
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 }
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 }
相关文章推荐
- BlogEngine.Net架构与源代码分析系列part14:实现分析(下)——网站页面上值得参考的部分
- 加载URL获得页面源代码
- python3-练习-爬取网站-中文编码-获取页面源代码-保存文件
- 网站源代码获得方法
- aspx页面中是这样获得网站根目录的物理路径的
- 网站响应式页面查看工具源代码
- 扒皮下腾讯网站地图页面页卡的滚动特效
- 令你的网站获得任意Google PR值的方法!
- 使用PHP提取视频网站页面中的FLASH地址
- icomoon网站辅助HTML页面插入图标①
- 在含有Request.QueryString页面中处理未能获得参数的错误处理方法
- Nginx网站自定义404错误页面
- jQuery获得页面元素的绝对/相对位置
- IIS部署网站问题 您正在搜索的页面可能已经删除、更名或暂时不可用。
- [转]Asp.net mvc 网站之速度优化 -- 页面缓存
- MOSS 2007 错误: 网站无效。缺少”页面“文档库。
- ASP用xmlhttp获得网页源代码
- phpcms网站前台页面访问正常,但是输入后台地址后,一片空白,没有任何错误提示
- 雅虎网站页面性能优化的34条黄金守则
- 网站建设页面设计中CSS正确书写