代码如下:
private void GetScoreCallback(IAsyncResult result)
{
try
{
HttpWebRequest request = (HttpWebRequest)result.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
resData = reader.ReadToEnd();
ProcessResponseScore();
}
catch (Exception ee)
{
errorAsync = ee;
}
}
其中网页的源码保存在resData中,我通过MessageBox.Show()查看发现它的中文都是乱码,该如何处理呢?
------解决方案--------------------------------------------------------
http://encoding4silverlight.codeplex.com/
------解决方案--------------------------------------------------------
private void GetScoreCallback(IAsyncResult result)
{
try
{
HttpWebRequest request = (HttpWebRequest)result.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream,new HtmlAgilityPack.Gb2312Encoding());
resData = reader.ReadToEnd();;
ProcessResponseScore();
}
catch (Exception ee)
{
errorAsync = ee;
}