I am creating the ASP.NET which is calling a third party Rest API. The third party API can be accessed only giving username and password. Also uses Http Basic Authentication
public string Get(string LabName)
{
string userName = ConfigurationManager.AppSettings["username"];
string password = ConfigurationManager.AppSettings["password"];
string BaseURL = ConfigurationManager.AppSettings["BaseURL"];
using (var client = new HttpClient())
{
Uri uri = new Uri(BaseURL);
client.BaseAddress = uri;
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
string clarity_URL = BaseURL+"api/v2/labs?name="+LabName;
var response = client.GetAsync(clarity_URL).Result;
string responseString = response.Content.ReadAsStringAsync().Result;
return responseString;
Should I be using HttpClient or HttpWebRequest.I am not sure how to pass the username and password while calling the Rest API in the ASP.NET.Can anyone suggest me how to securely call the API