string url = "www.baidu.com";
string url2="www.xxxx.com";
string url3 ="www.xxxx2.com"
.......
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream s = response.GetResponseStream();
StreamReader sr = new StreamReader(s, Encoding.GetEncoding("gb2312"));
MessageBox.Show(sr.ReadToEnd());
sr.Dispose();
sr.Close();
s.Dispose();
s.Close();
請問下 我怎麼把那三條url 一起執行一遍呢? 放到數組裡面去嗎?
string url = "www.baidu.com";
string url2="www.xxxx.com";
string url3 ="www.xxxx2.com";
string[] urls = { url, url1, url2 };
foreach (var u in urls)
{
WebRequest request = WebRequest.Create(u);
WebResponse response = request.GetResponse();
Stream s = response.GetResponseStream();
StreamReader sr = new StreamReader(s, Encoding.GetEncoding("gb2312"));
MessageBox.Show(sr.ReadToEnd());
sr.Dispose();
sr.Close();
s.Dispose();
s.Close();
}