该类XmlReader
无法解析来自 URL 的身份验证信息,您必须创建一个XmlSettings
实例并将其XmlResolver
属性设置为一个XmlUrlResolver
实例,该实例的凭据设置为用户名和密码。然后,当您创建XmlReader
实例时,您提供自定义XmlSettings
实例。以下代码可以解决问题:
// Create a resolver with your credentials
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = new NetworkCredential("myusername", "mypassword");
// Set the reader settings object to use the resolver.
XmlReaderSettings settings = new XmlReaderSettings();
settings.XmlResolver = resolver;
string url = "https://mail.google.com/mail/feed/atom";
// Create the reader using the specified URL and settings
XmlReader reader = XmlReader.Create(url, settings);
SyndicationFeed feed = SyndicationFeed.Load(reader);
reader.Close();
但是,我尝试了此代码并XmlException
抛出以下内容:
“名称为 'feed' 和命名空间 ' http://purl.org/atom/ns# '的元素不是允许的提要格式。”
Google 输出的提要格式似乎与SyndicationFeed
该类不兼容。欲了解更多信息,请参阅:http ://www.eggheadcafe.com/tutorials/csharp/9faa101f-0a1a-465f-a41a-3e52dd9f7526/everything-rss--atom-feed-parser.aspx