方法一:采用 WebClient ,代码如下
using System.Net;
{
string strurl="网址";
WebClient aWebClient = new WebClient();
aWebClient.Encoding = System.Text.Encoding.UTF8;
string htmlcode = aWebClient.DownloadString(strurl);
txtbox.Text=htmlcode;//txtbox为一个文本框
}
方法二:采用 HttpWebRequest HttpWebResponse ,代码如下
using System.Net;
{
string strurl = "http://www.weather.com.cn/weather/101310101.shtml?from=cn";
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(strurl);
myReq.Accept = "Accept-Languat:zh-cn";
myReq.AllowAutoRedirect = true;
myReq.MaximumAutomaticRedirections = 1;
myReq.Referer = "weather";
HttpWebResponse myResponse = (HttpWebResponse)myReq.GetResponse();
Stream myStream = myResponse.GetResponseStream();
StreamReader myReader = new StreamReader(myStream, System.Text.Encoding.UTF8);
txtbox.Text = myReader.ReadToEnd();//txtbox为一个文本框
}