C#获得指定网页的源代码
在软件开发中经常因为一些原因需要获得网页的源代码,在.NET2.0中使用WebClient可以轻松实现这个功能。
private void button1_Click(object sender, EventArgs e)
{
string uri = textBox1.Text;
WebClient myClient = new WebClient();
byte[] myBytes = myClient.DownloadData(uri);
textBox2.Text = Encoding.Default.GetString(myBytes);
myClient.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
string uri = textBox1.Text;
WebClient myClient = new WebClient();
byte[] myBytes = myClient.DownloadData(uri);
textBox2.Text = Encoding.Default.GetString(myBytes);
myClient.Dispose();
}