显示网页HTML源代码
1)引入命名空间
2)添加一个button,一个textbox,一个listbox
3)加入button事件
using System.Net;
using System.IO;
using System.IO;
2)添加一个button,一个textbox,一个listbox
3)加入button事件
1private void button1_Click(object sender, EventArgs e)
2{
3 string netUrl = "http://"+textBox1.Text;
4 string line;
5 WebClient client = new WebClient();
6 Stream strm = client.OpenRead(netUrl);
7 StreamReader sr = new StreamReader(strm);
8
9 while((line=sr.ReadLine())!=null)
10 {
11 listBox1.Items.Add(line);
12 }
13 strm.Close();
14}
2{
3 string netUrl = "http://"+textBox1.Text;
4 string line;
5 WebClient client = new WebClient();
6 Stream strm = client.OpenRead(netUrl);
7 StreamReader sr = new StreamReader(strm);
8
9 while((line=sr.ReadLine())!=null)
10 {
11 listBox1.Items.Add(line);
12 }
13 strm.Close();
14}