winform获取网页代码的两种方式:

1.使用WebClient类获取:

   1:  WebClient wc1 = new WebClient();
   2:  wc1.Encoding = Encoding.UTF8;
   3:   string weatherData1 = wc2.DownloadString(http://www.weather.com.cn/data/sk/101280601.html);

 

 

2.使用网页流:

 

   1:              HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.weather.com.cn/data/sk/101280601.html");
   2:              request.Timeout = 5000;
   3:              request.Method = "GET";
   4:              HttpWebResponse response = (HttpWebResponse)request.GetResponse();
   5:              StreamReader sr = new StreamReader(response.GetResponseStream());
   6:              string jsonstr = sr.ReadLine();
posted @ 2014-04-03 09:09  草旅虫  阅读(393)  评论(0编辑  收藏  举报