C# webclient中文乱码问题解决方法
webclient在调用DownloadData或者DownloadString的时候请求回来的数据出现乱码问题,解决办法如下:
1、设置webclient的编码格式为目标编码格式
WebClientweb=newWebClient();//创建webclient对象
web.Encoding=System.Text.Encoding.UTF8;//定义对象语言
stringreturns=web.DownloadString("_http://www.weather.com.cn/data/sk/101310101.html");//向一个连接请求资源
2、先获取数据,然后转码
WebClientwc=newWebClient();
Byte[]pageData=wc.DownloadData("http://m.weather.com.cn/data/101110101.html");
stringrr=Encoding.GetEncoding("utf-8").GetString(pageData);
总结下来,还是编码的问题,不论哪种方法,设置好编码即可。
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短