I am trying to get data from this api codaBox I've tested it with swagger but when I am trying with c# I am getting a error code 401. I am using the right header, username and password.
I tested it with swagger with the same credentials and I've got data with it.
try
{
var byteArray = Encoding.ASCII.GetBytes("Username:password");
Client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
Client.BaseAddress = new Uri("https://myurl");
Client.DefaultRequestHeaders.Add("X-Software-Company", "myToken");
HttpResponseMessage response = await Client.GetAsync("");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
// Above three lines can be replaced with new helper method below
// string responseBody = await client.GetStringAsync(uri);
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
}
I would like to get 200 status code.