1.需求
获得网页数据,并填充到webbrowser空间中
2.代码示例
private void button1_Click_1(object sender, EventArgs e)
{
//1.浏览的url
string url = textBox1.Text;
//2.创建请求链接
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
//3.获得响应实例
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //GetResponse:获取答复
//4.构造数据流实例
Stream stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
//5.从流当前位置读取到末尾并显示在WebBrower控件中
string content = sr.ReadToEnd();
webBrowser1.DocumentText = content;
}