I'm trying to make a HttpClient Call through C# by adding some headers. The request is working fine by throwing the empty result as expected with 200 status code. But the same is not working in C# code. My code is like below :
public static Response TestAbcAPICall()
{
Response response = new Response();
try
{
var endpoint = "https:/abc.com/path/?script=435&deploy=1&type=vendor&id=9797";
using (var client = new System.Net.Http.HttpClient())
{
client.BaseAddress = new Uri(endpoint);
//way - 1 Adding Authorization header
var authenticationHeaderValue = new AuthenticationHeaderValue("Authorization", "NLAuth nlauth_account=1249484_SKB1, nlauth_email=restletuser1@org.in, nlauth_signature=Breaths123!, nlauth_role=4444");
client.DefaultRequestHeaders.Authorization = authenticationHeaderValue;
// Adding contennt-type header
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var getTask = client.GetAsync(endpoint);
getTask.Wait();
var result = getTask.Result;
if (result.IsSuccessStatusCode)
{
var RESULTS = result.Content.ReadAsStringAsync().Result;
//response = JsonConvert.DeserializeObject<Response>(RESULTS);
if (response.flag)
{
response.flag = true;
}
else
{
response.flag = false;
}
}
}
}
catch (Exception ex)
{
response.message = ex.Message;
response.flag = false;
}
return response;
}