Search code examples
c#.netxmlasp.net-mvcxmlreader

Xml reader - (403) Forbidden


I use Xml reader to read some blogs feed like this:

var reader = XmlReader.Create(url);

I'm getting an error with some urls:

{"The remote server returned an error: (403) Forbidden."}

If I open this url in my browser it works well.

Do you have any idea what's wrong?


Solution

  • You can supply credentials for the XmlReader to use when accessing a URL; which is likely what you need to do in your circumstance. see https://msdn.microsoft.com/en-us/library/47as68k4(v=vs.71).aspx for details.

    You could also use an HttpClient object with credentials to get the response as a Stream and use XmlReader.Create(Stream) instead.