通过点击查看“html源码”按钮就弹出一个对话框显示博客园首页的html源码 private string GetCnBlogs() { string html = String.Empty; HttpWebRequest cnbogs = (HttpWebRequest)System.Net.WebRequest.Create(txtURL.Text.ToString()); cnbogs.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, */*"; cnbogs.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; MALN; CIBA; InfoPath.2; .NET4.0C; .NET4.0E; Media Center PC 6.0; Tablet PC 2.0; AskTB5.6)"; cnbogs.Method = "GET"; HttpWebResponse cnblogsRespone = (HttpWebResponse)cnbogs.GetResponse(); if (cnblogsRespone != null&&cnblogsRespone.StatusCode==HttpStatusCode.OK) { using(StreamReader sr = new StreamReader(cnblogsRespone.GetResponseStream())) { html = sr.ReadToEnd(); } } return html; } private void btnGetHtml_Click(object sender, EventArgs e) { MessageBox.Show(GetCnBlogs()); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。