日期:2014-05-20  浏览次数:20392 次

专送分给孟子E章--RSS解析和获取网页原代码问题
如题
按照孟子E章的文章
http://dotnet.aspx.cc/ShowDetail.aspx?id=0A6660CE-4138-41EF-B882-15DB65564709

大多数网页能解析获得网页原代码,但一部分会出现(404)   NOT   FOUND的异常,但这样网址能在IE中直接打开,搞了很久,找了很多资料,换了很多方法仍然不知道缘由,盼孟子E章帮忙,谢谢先

附这样地址:
http://www.blogcn.com/rss2/06sg.xml
http://www.blogcn.com/rss2/liasura.xml
...

------解决方案--------------------
string PageUrl = "http://www.blogcn.com/rss2/06sg.xml ";
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(PageUrl);
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1) Web-Sniffer/1.0.24 ";
System.Net.WebResponse response = request.GetResponse();
System.IO.Stream resStream = response.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(resStream, System.Text.Encoding.Default);
ContentHtml.Text = sr.ReadToEnd();
resStream.Close();
sr.Close();