Greetings
I’m trying to get an xml file from a website which requires me to fill in a username and API key.
Example:
public void GetTournaments(string userName, string apiKey, string tournamentName)
{
string getXMLAdress = "https://" + userName + ":" + apiKey + "@challonge.com/api/tournaments/" + tournamentName + "/participants.xml";
XmlDocument tournamentsXML = new XmlDocument();
tournamentsXML.Load(getXMLAdress);
}
The API on the website shows that you only need this information.. however it always returns a 401 that I have no access. Now I noticed when I put this in my browser I still had to fill in my Username and password as well. When using the above URL it shows a popup box where you can fill in your username/password.
I could always let users download the files themselves but that would be kind of an hassle. So I’m wondering if there is an alternative way or if I can fill in the popup box through C#.
Thank you in advance.
You can pass in the credentials through a WebClient and use it to load the required XML file from the Web Server.
If the userName contains domain information, do pass it separately in the overloaded constructor of
NetworkCredential(string userName, string password, string domain)Hope that helps!