I´m trying to access a website where I can download a .Json
, however the site has a userID and PWD. I have the credentials for it and the site are using Basic authentication (basich auth (base64 encoded password) ) I do not know if im on the right track or if I can access the site with userid and pwd in another way?
using (var webClient = new System.Net.WebClient())
{
webClient.Credentials = new NetworkCredential("username", "pwd");
var json = webClient.DownloadString("https://tracking.com/delivery/api/fetch-transactions?fromDate=2020-01-01");
List<Example> list = JsonConvert.DeserializeObject<List<Example>>(json);
}
looks like its not opening the url with userid and pwd...
This one worked for me:
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));
webClient.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;