HttpWebRequest获取网页,中文字符为何变成乱码?
本程序在Microsoft Visual Web Developer 2005 Bata2中文版下调试:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mr As HttpWebRequest
Dim mt As HttpWebResponse
Dim sr As StreamReader
Dim li As String
mr = CType(WebRequest.Create("http://www.163.com/"), HttpWebRequest)
mt = CType(mr.GetResponse(), HttpWebResponse)
sr = New StreamReader(mt.GetResponseStream())
li = sr.ReadLine()
Do While Not li Is Nothing
li = HttpUtility.HtmlEncode(li)
If li.Length <> 0 Then
Response.Write(li & "<BR>")
End If
li = sr.ReadLine()
Loop
End Sub
得到如下页面:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>????</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="content-language" content="gb2312" />
<style type=text/css>
<!--
html {min-width:750px;}
body {text-align:center; margin:0px;}
body > div {text-align:center; margin-right:auto; margin-left:auto;}
form, input, select {margin:0px; padding:0px;}
body, div {font-size:12px; font-family:????;}
img,a img{border:0; margin:0; padding:0;}
input,select{font-size:12px;vertical-align:middle}
/*=====urs??½??=====*/
#UrsLogin {border:1px solid #ccc; background:#EBEBEB; padding:2px; width:744px!important; width /**/:750px; height:22px!important; height /**/:28px;}
#userName,#password{width:73px}
#userName{color:#aaa}
#loginSelect{width:90px}
/*=====????Logo & Ƶ??????=====*/
<div class="Text1">
<a href="http://ent.163.com/star/">????</a> <a href="http://ent.163.com/special/c/00031JN6/chaonv2005.html">"??Ů"????</a> <a href="http://ent.163.com/05/0914/09/1TJN616H00031H2F.html">?????˷??DZ????Ľ?ֹ</a><br /><a href="http://bbs.netease.com/game/index.php?forumcode=273">?ڲ????룡???ס????ơ?18?????</a><br /><a href="http://app.game.163.com/caicai/">??ϷIQ???ƴ???Ҳ???Ŀ¡???Ƴ???</a><br />
</div>
<div class="Text2">
<a href="http://education.163.com/">????</a> <a href="http://education.163.com/">?????߿??Ծ??????</a> <a href="http://education.163.com/kaoyan/">2006???м???</a></a><br /><a </h3>
</div>
<!-- ????logo3 Start -->
<div id="Logo300">
<iframe src="http://adclient.163.com/html.ng/site=netease&affiliate=homepage&cat=homepage&type=logo300120&location=3" width="300" height="120" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div>
<!-- ????logo3 End -->
<!-- ????̬ Start-->
<div id="Netease">
<h2 class="Title2">
<div>????̬ ?? </div><a href="http://design.163.com/newsletter/all/">????Ѷ</a>
</h2>
<div class="OneC">
??<a href="http://corp.163.com/corpnews/editor/050907/050907_2698.html">??2??"????ȫ??ժ?Ǵ??ж?"?????ܾ???????????</a><br />
??<a href="http://gb.corp.163.com/corpnews/editor/050901/050901_2694.html">?°?POPO???????黶?????ɹ?ͨ</a><br />
??<a href="http://gb.corp.163.com/corpnews/editor/050803/050803_2692.html">??????2005??ڶ????ȲƱ?????????2930????Ԫ</a><br />
??<a href="http://corp.163.com/corpnews/index.html">????</a>...
</div>
</div>
<!-- ????̬ End-->
</div>
</div>
<<…………………………
</script>
<noscript>
<img src="//secure-cn.imrworldwide.com/cgi-bin/m?ci=cn-netease&cg=0" alt="">
</noscript>
<!-- END NNR Site Census V5.1 -->
</body>
</html>
以上内容只要是中文的地方都是乱码,请问应该如何解决?谢谢!(但在获取www.liall.com这个页面时却不会出现任何异常现象)