c#获取网页内容的三种方法
1.webclient
WebClient wc = new WebClient();
Stream stm = wc.OpenRead(str_url);
StreamReader sr = new StreamReader(stm,Encoding.UTF8);
//Encoding这个类的属性有:UTF8,Unicode等等
Console.Write(sr.ReadToEnd());
2.
HttpWebRequest hwrq = (HttpWebRequest)WebRequest.Create(str_url);
HttpWebResponse hwrp = (HttpWebResponse)hwrq.GetResponse();
StreamReader sr = new StreamReader(hwrp.GetResponseStream(),Encoding.UTF8);
Console.Write(sr.ReadToEnd()); Stream st = WebRequest.Create(str_url).GetResponse().GetResponseStream();
StreamReader str = new StreamReader (st,Encoding.UTF8);
Console .Write(str.ReadToEnd ());
3.
string str_url = "http://www.baidu.com/";
WebClient wclient = new WebClient();
string str_content = wclient.DownloadString(str_url);
byte[] bt_content = new byte[str_content.Length];
bt_content = Encoding.Default.GetBytes(str_content); //此处不可吧Default转换成UTF8,否则造成转了两次,就乱码了。
str_content = Encoding.UTF8.GetString(bt_content);
Console.WriteLine(str_content);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
c#获取网页内容的三种方法的更多相关文章
- 体温数据上传程序开发+获取时间的三种方法+DB Browser下载及安装
今天开始了体温上传程序的开发 今日所学: 获取时间 (21条消息) (转)安卓获取时间的三种方法_sharpeha的博客-CSDN博客_安卓获取时间 DB Browser安装教程 (20条消息) sq ...
- java 获取随机数的三种方法
方法1(数据类型)(最小值+Math.random()*(最大值-最小值+1))例:(int)(1+Math.random()*(10-1+1))从1到10的int型随数 方法2获得随机数for (i ...
- URL转Drawable之 Android中获取网络图片的三种方法
转载自: http://doinone.iteye.com/blog/1074283 Android中获取网络图片是一件耗时的操作,如果直接获取有可能会出现应用程序无响应(ANR:Applicatio ...
- C#获取网页内容的三种方式
C#通常有三种方法获取网页内容,使用WebClient.WebBrowser或者HttpWebRequest/HttpWebResponse... 方法一:使用WebClient (引用自:http: ...
- C#获取网页内容的三种方式(转)
搜索网络,发现C#通常有三种方法获取网页内容,使用WebClient.WebBrowser或者HttpWebRequest/HttpWebResponse... 方法一:使用WebClient (引用 ...
- android系统通过图片绝对路径获取URI的三种方法
最近做项目要通过图片的绝对路径找到图片的URI,然后删除图片,小小总结一下获取URI的方法,亲自试验在 android 4.1.3的系统上都是可用的. 1.将所有的图片路径取出,遍历比较找到需要的路径 ...
- js jquery 获取服务器控件的三种方法
由于ASP.NET网页运行后,服务器控件会随机生成客户端id,jquery获取时候不太好操作,google了下,总结有以下3种方法: 服务器控件代码:<asp:TextBox ID=" ...
- 获取IP的三种方法
第一种 取本主机ip地址 public string GetLocalIp() { ///获取本地的IP地址 string AddressIP = string.Empty; foreach (IPA ...
- PHP获取网页内容的几种方法
方法1: 用file_get_contents以get方式获取内容 <?php $url='http://www.domain.com/?para=123'; $html= file_get_c ...
随机推荐
- PL/pgSQL学习笔记之三
http://www.postgresql.org/docs/9.1/static/plpgsql-overview.html 39.1.2. Supported Argument and Resul ...
- MySQL中MySQL X.X Command Line Client一闪而过的问题
问题介绍:我安装完MySQL(我安装的是5.5)后,使用MySQL 5.5 Command Line Client,每次点击,总是一闪而过.解决方法如下: 首先进入cmd 切入MySQL的安 ...
- Codeforces Gym 100463D Evil DFS
Evil Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Descr ...
- GLSL-几何着色器详解跟实例(GS:Geometry Shader)[转]
[OpenGL4.0]GLSL-几何着色器详解和实例(GS:Geometry Shader) 一.什么是几何着色器(GS:Geometry Shader) Input Assembler(IA)从顶点 ...
- 对.NET中Hashtable和ArryList的理解
1.HashTabel 在.NET Framework中,Hashtable是System.Collections命名空间提供的集合对象,同时它也是一个可变长的数组,用于处理和表现类似key/valu ...
- 1028 - Carl the Ant
Ants leave small chemical trails on the ground in order to mark paths for other ants to follow. Ordi ...
- Golang学习 - sync 包
------------------------------------------------------------ 临时对象池 Pool 用于存储临时对象,它将使用完毕的对象存入对象池中,在需要 ...
- No Entertainment!
今天决定去打印一个“No Entertainment”的横幅,贴在电脑的旁边.这其实是很久以前的事了,却搁浅到了现在.也正因为如此,今天想起来也觉得格外刻不容缓,内心好似义愤填膺,便写下这愤慨的独白. ...
- jstree 插件的使用笔记(一)
官方:http://www.jstree.com/ 一.节点的描述 官方资料:http://www.jstree.com/docs/json/ 格式一 { id : "string&quo ...
- Spark installation for windows
download spark from spark.apache.org download hadoop from hadoop.apache.org download hadoop.dll and ...