您现在的位置是:网站首页> 编程资料编程资料
ASP.NET使用HttpWebRequest读取远程网页源代码_实用技巧_
2023-05-24
234人已围观
简介 ASP.NET使用HttpWebRequest读取远程网页源代码_实用技巧_
读取远程网页能做什么就不用多说了吧,做小偷程序或是采集,也就诸如此类了吧。
public string GetPage(string url) { HttpWebRequest request = null; HttpWebResponse response = null; StreamReader reader = null; try { request = (HttpWebRequest)WebRequest.Create(url); request.Timeout = 20000; request.AllowAutoRedirect = false; response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK && response.ContentLength < 1024 * 1024) { reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default); string html = reader.ReadToEnd(); return html; } } catch { } finally { if (response != null) { response.Close(); response = null; } if (reader != null) reader.Close(); if (request != null) request = null; } return string.Empty; }您可能感兴趣的文章:
相关内容
- ASP.NET过滤类SqlFilter,防止SQL注入[原创]_实用技巧_
- 基于.NET平台常用的框架和开源程序整理_自学过程_
- ASP.NET在底层类库中获取Session C#类中获取Session[原创]_实用技巧_
- GridView导出Excel常见的5种文本格式[原创]_实用技巧_
- 全面剖析.Net环境下的缓存技术_实用技巧_
- ADO.NET通用数据库访问类_实用技巧_
- ASP.NET MVC异常处理模块详解_实用技巧_
- ASP.NET/C#中如何调用动态链接库DLL_实用技巧_
- asp.net实现调用存储过程并带返回值的方法_实用技巧_
- asp.net实现调用带有输出参数的存储过程实例_实用技巧_
