using System.Net;string strUrl = "http://gather.sohu.com/life/forecast/query.asp?cityname=";
strUrl =  strUrl + System.Web.HttpUtility.UrlEncode("北京", System.Text.Encoding.GetEncoding("gb2312"));
string strUrl = "http://www.sina.com.cn";
HttpWebRequest oRequest = (HttpWebRequest)WebRequest.Create(strUrl);HttpWebResponse oResponse  = (HttpWebResponse)oRequest.GetResponse();
StreamReader sr = new StreamReader(oResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("GB2312"));string sResultContents = sr.ReadToEnd();
oResponse.Close();
byte[]  bytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(sResultContents);
FileStream fs = new FileStream("c:\\2.htm", FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();

解决方案 »

  1.   

    //string strUrl = "http://www.sina.com.cn";
      

  2.   

    也就是需要一个类似Connect(userID,pwd)的函数去连接,
    如何做???
      

  3.   

    string strHtml = null;
    Encoding strEncode = System.Text.Encoding.GetEncoding("UTF-8");
    string strAction = "http://...";
    string strData = "userID=" + strUserID + "&pwd=" + strPwd;HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strAction);
    req.UserAgent = "MSIE6.0";
    req.Method = "POST";
    byte[] PostData = System.Text.Encoding.ASCII.GetBytes(strData);
    req.ContentLength = PostData.Length;
    Stream tempStream = req.GetRequestStream();
    tempStream.Write(PostData, 0, PostData.Length);
    tempStream.Close();HttpWebResponse res = (HttpWebResponse)req.GetResponse();
    StreamReader sr = new StreamReader(res.GetResponseStream(), strEncode);
    strHtml = sr.ReadToEnd();
    sr.Close();
    res.Close();