Cieja Cieja - 4 years ago 151
C# Question

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?

Answer Source

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 for details.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download