Maharudra Gadekar

Maharudra Gadekar

  • 1.4k
  • 367
  • 81.4k

how to pass some parameter in header and some in query strin in webapi

Mar 18 2021 10:37 AM
Hi,
 
i am using webapi and I am stuck in how to pass parameter in header and querystring single time.
Can you help me please .
 
Look at below code.
 
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("para1", "para1");
client.DefaultRequestHeaders.Add("para2", "para2");
client.DefaultRequestHeaders.Add("para2", "para2");
HttpResponseMessage response1 = client.GetAsync("https://test.com/api/[email protected]").Result;
 
if (response1.IsSuccessStatusCode)
{
var result = response1.Content.ReadAsStringAsync().Result;
}
else
{
//Something has gone wrong, handle it here
}
 
 
Please help me
 
Thanks in advance. 

Answers (3)