0

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.

Flo
  • 6,070
  • 26
  • 97
  • 171
  • I haven't had a chance to try this out yet, but this might be helpful: https://stackoverflow.com/questions/5507234/how-to-use-basic-auth-with-jquery-and-ajax?answertab=oldest#tab-top – Gene Parcellano Nov 02 '17 at 19:56

1 Answers1

1

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");
}
James
  • 893
  • 9
  • 17