Updating custom header value added as DefaultRequestHeaders of HttpClient
The error I was getting: An item with the same key has already been added. Key: x
Example code for mahesh_ing answer:
var request = new HttpRequestMessage
{
Method = this.method,
RequestUri = new Uri(this.requestUri),
};
request.Headers.Add("Key", "Value");
var client = new System.Net.Http.HttpClient
{
Timeout = this.timeout
};
return await client.SendAsync(request);
I added header to actual (current) request using HttpRequestMessage and replaced a call with SendAsync instead of GetAsync and it resolved my issue. Thanks @levent.