获得html页面的方法如下:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string strURL = this.Page.Request.QueryString["FN"] ; // create a new uri object with the node's target 
Uri myUri = new Uri(strURL) ; // create a new request to the above mentioned URL.
WebRequest myWebRequest = WebRequest.Create(myUri) ; // Set the ContentType property
myWebRequest.ContentType = "application/x-www-from-urlencoded" ; System.Text.Encoding.GetEncoding("GB2312");

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse = myWebRequest.GetResponse() ; // get response stream to a stream object 
Stream streamResponse = myWebResponse.GetResponseStream() ; StreamReader streamRead = new StreamReader(streamResponse) ; string strResponse = streamRead.ReadToEnd() ; // show the stream to the table 
this.Table1.Rows[0].Cells[0].InnerHtml = strResponse ; // Close the response to free resources.
myWebResponse.Close() ; }
**************************************************************************************
但是在页面上显示的时候,总文显示为乱码。大家有什么好意见,请帮帮忙好么?

解决方案 »

  1.   

    StreamReader streamRead = new StreamReader(streamResponse,Encoding.GetEncoding("GB18030"))
      

  2.   

    谢谢兄弟!能否交个朋友?我的[email protected]
      

  3.   

    参考:try
    {
    string fullpath = @"http://www.baidu.com"; 
    HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(fullpath);
    HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
    StreamReader strm = new StreamReader(webresp.GetResponseStream(), Encoding.Default);
    string ret= strm.ReadToEnd();
    MessageBox.Show (ret);
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
      

  4.   

    GetEncoding 方法依赖于基础平台支持大部分代码页。但是,对于下列情况提供系统支持:默认编码,即在执行此方法的计算机的区域设置中指定的编码;Little-Endian Unicode (UTF-16LE);Big-Endian Unicode (UTF-16BE);Windows 操作系统 (windows-1252);UTF-7;UTF-8;ASCII 以及 GB18030(简体中文)。