日期:2014-05-18 浏览次数:21100 次
WebClient webclient = new WebClient(); webclient.Proxy = null; byte[] buf = webclient.DownloadData(url); return Encoding.Default.GetString(buf);
WebClient webclient = new WebClient(); webclient.Proxy = null; byte[] buf = webclient.DownloadData("http://u17.com"); string result= Encoding.GetEncoding("utf-8").GetString(buf);//默认的编码 //为GB2312,有些网站采用utf8编码规则,默认的编码规则就会遇到中文会出现乱码
------解决方案--------------------
WebClient webclient = new WebClient();
webclient.Proxy = null;
byte[] buf = webclient.DownloadData("http://u17.com/");
System.IO.MemoryStream mem = new MemoryStream(buf);
System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(mem, System.IO.Compression.CompressionMode.Decompress);
StreamReader reader = new StreamReader(gzip);
return reader.ReadToEnd();