Pass Custom Headers Using HttpClient C# REST API

Viewed 20

Im consuming a REST api, and i need to pass custom header values auth-forward,nonce and createdon expected by the api. Below is my code, im getting the error suggesting the values are not being passed

   HttpClient client3 = new HttpClient();
   client3.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", access_token);
        **client3.DefaultRequestHeaders.Add("auth-forward", AUTH_FORWARD);
        client3.DefaultRequestHeaders.Add("nonce", NONCE);
        client3.DefaultRequestHeaders.Add("createdon", "2022-09-07T21:00:49.514+03:00");**
        HttpResponseMessage response3 = await client3.GetAsync(get_personapi+req.nationalId);
        HttpContent content3 = response3.Content;
        string result3 = await content3.ReadAsStringAsync();
        JObject jObject3 = JObject.Parse(result3);
        return new JsonResult(result3);
0 Answers
Related