日期:2014-05-17 浏览次数:20789 次
public static string GetHtml(string url, Encoding encoding) { HttpWebResponse response = null; Stream dataStream = null; StreamReader reader = null; try { WebRequest request = WebRequest.Create(url); request.Credentials = CredentialCache.DefaultCredentials; request.Timeout = 300000; response = (HttpWebResponse)request.GetResponse(); dataStream = response.GetResponseStream(); reader = new StreamReader(dataStream, encoding); return reader.ReadToEnd(); } catch (Exception ex) { WriteLog(ex); return ""; } } 使用上面这个方法获取网页的源码,出现中文乱码,但不是所有的中文都是乱码,只是部分出现乱码,如: <table width="90%" border="0" cellspacing="1" cellpadding="1" class="font" align="center"> <tr bgcolor="#CADBFF"> <td bgcolor="#CADBFF" width="15%" align="right" height="25">箱号:</td> <td width="35%" bgcolor="#ACBEFF"> WHLU2412918 </td> <td width="15%" bgcolor="#CADBFF" align="right">尺寸:</td> <td width="35%" bgcolor="#ACBEFF"> 20?卞昂 </td> </tr> <tr bgcolor="#E6EDFD" > <td bgcolor="#CADBFF" width="15%" align="right" height="25">箱型:</td> <td width="35%" > </td> <td width="15%" bgcolor="#CADBFF" align="right" >高度:</td> <td width="35%" > 8?卞昂6?卞? </td> </tr> <tr bgcolor="#ACBEFF" > <td bgcolor="#CADBFF" width="15%" align="right" height="25" >状态:</td> <td width="35%" bgcolor="#ACBEFF" > ?哄???? </td> 我试过好几种获取源码的方法,都不能解决这个问题?请问如何解决这个问题呢?