The XmlReader
class cannot parse authentication information from the URL, you have to create an XmlSettings
instance and set its XmlResolver
property to an XmlUrlResolver
instance that has its credentials set to the username and password. Then when you create the XmlReader
instance, you supply the custom XmlSettings
instance. The following code would do the trick:
// Create a resolver with your credentialsXmlUrlResolver 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 settingsXmlReader reader = XmlReader.Create(url, settings);SyndicationFeed feed = SyndicationFeed.Load(reader);reader.Close();
However, I tried this code and the following XmlException
was thrown:"The element with name 'feed' and namespace 'http://purl.org/atom/ns#' is not an allowed feed format."
It appears that the feeds Google outputs are in a format that is incompatible with the SyndicationFeed
class. For more information see: http://www.eggheadcafe.com/tutorials/csharp/9faa101f-0a1a-465f-a41a-3e52dd9f7526/everything-rss--atom-feed-parser.aspx