我想通过RSS获取Inbox,我可以在使用Response.Redirect时获取XML,但无法获取XML格式,它会抛出(401)未经授权的错误我的代码
string url = "https://myusername:mypassword@mail.google.com/mail/feed/atom";
XmlReader reader = XmlReader.Create(url);
SyndicationFeed feed = SyndicationFeed.Load(reader);
reader.Close();
- > Response.Redirect的(URL); //这是工作 谁能对它有任何想法, 要么 是任何版本的AE.Net.Mail.dll for Framework 2.0
谢谢你
答案 0 :(得分:1)
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#'的元素不是允许的Feed格式。”
Google Feed输出的格式似乎与SyndicationFeed
类不兼容。有关详细信息,请参阅:http://www.eggheadcafe.com/tutorials/csharp/9faa101f-0a1a-465f-a41a-3e52dd9f7526/everything-rss--atom-feed-parser.aspx