c# httpgethtml
来源:互联网 发布:作曲的软件 编辑:程序博客网 时间:2024/06/05 07:56
c# httpgethtml
public string GetHtmlFromGet(string urlString) { //定义局部变量 HttpWebRequest httpWebRequest = null; HttpWebResponse httpWebRespones = null; Stream stream = null; string htmlString = string.Empty; //请求页面 try { httpWebRequest = WebRequest.Create(urlString) as HttpWebRequest; } //处理异常 catch (Exception ex) { throw new Exception("建立页面请求时发生错误!", ex); } httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; Maxthon 2.0)"; //获取服务器的返回信息 try { httpWebRespones = (HttpWebResponse)httpWebRequest.GetResponse(); stream = httpWebRespones.GetResponseStream(); } //处理异常 catch (Exception ex) { throw new Exception("接受服务器返回页面时发生错误!", ex); } StreamReader streamReader = new StreamReader(stream,Encoding .UTF8); //读取返回页面 try { htmlString = streamReader.ReadToEnd(); } //处理异常 catch (Exception ex) { throw new Exception("读取页面数据时发生错误!", ex); } //释放资源返回结果 streamReader.Close(); stream.Close(); return htmlString; }
0 0
- c# httpgethtml
- C#
- C#
- C#
- C#
- C#
- C#
- C#
- C#
- C#
- C#
- C#
- c#
- c#
- C#
- C#
- C#
- c#
- matlab在数字图像处理中的小笔记(1)
- MySQL This function has none of DETERMINISTIC, NO SQL...错误1418 的原因分析及解决方法
- __thread 用法
- mysql报./ib_logfile0 启动失败解决办法
- 实现APP进入登录界面之前的动画效果
- c# httpgethtml
- IOS UIAlertController 弹框 (ios 9.0 后代替了UIAlertView弹框 和 UIActionSheet下弹框)
- hdu 1998 奇数阶魔方
- 关于android:configChanges的属性
- 【leetcode】【100】Same Tree
- Android 中重写TextView实现 跑马灯 最简单的方法
- 上拉加载-下拉刷新控件 RefreshListView
- 消息队列的使用场景
- Codeforces 86D Powerful array(莫队算法)