Adam
Adam

Reputation: 6132

ASP.NET access file behind browser authentication prompt

I want to programmatically access a test XML feed on a 3rd party site which is behind a login, see an example below:

enter image description here

How can I pass the credentials to this site? Would I fill out this form programmatically? Is there a certain setup for the request url in which I can pass credentials? I googled but all I get is examples on authentication within an ASP.NET application. I'd appreciate an example.

Upvotes: 0

Views: 113

Answers (1)

James
James

Reputation: 1003

You need to pass a NetworkCredential containing the username and password to the WebClient you're using to fetch your data.

I've provided an example using WebClient below.

using (WebClient webClient = new WebClient())
{
    webClient.Credentials = new NetworkCredential("YourUsername", "YourPassword");
    string data = webClient.DownloadString("YourURL");
}

Upvotes: 1

Related Questions