我使用this解决方案从ASP.NET网站读取和解析RSS提要。这非常有效。但是,在另一个站点上尝试时,会出现错误,因为“系统不支持'utf8'编码。”下面我已经包含了我的代码摘录。
private void Form1_Load(object sender, EventArgs e)
{
lblFeed.Text = ProcessRSS("http://buypoe.com/external.php?type=RSS2", "ScottGq");
}
public static string ProcessRSS(string rssURL, string feed)
{
WebRequest request = WebRequest.Create(rssURL);
WebResponse response = request.GetResponse();
StringBuilder sb = new StringBuilder("");
Stream rssStream = response.GetResponseStream();
XmlDocument rssDoc = new XmlDocument();
rssDoc.Load(rssStream);
XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item");
string title = "";
string link = "";
...
错误发生在“rssDoc.Load(rssStream);”。任何正确编码xml的帮助都将受到赞赏。
答案 0 :(得分:3)
使用以下代码进行编码
System.IO.StreamReader stream = new System.IO.StreamReader
(response.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8"));