I am creating a base class, inherited by multiple clients to utilize. They all use different headers.
I have a set of header values I want to pass to my base class with the 'client' methods that set the client.DefaultRequestHeaders variable
AuthenticationHeaderValue x = new AuthenticationHeaderValue(authValue.Parameter);
NameValueHeaderValue y = new NameValueHeaderValue("AMSConnect-Version", "1_0_0");
NameValueHeaderValue y2 = new NameValueHeaderValue("AMSConnect-Environment", "Dev");
Normally, I'd set up something like this if I was only trying to interface with once API, and one set of of headers...
using (HttpClient client = new HttpClient(handler) { BaseAddress = baseAddress })
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", this.SttiServiceEnv.AccessToken);
client.DefaultRequestHeaders.Add("AMSConnect-Version", "1_0_0");
client.DefaultRequestHeaders.Add("AMSConnect-Environment", "Dev");
However, the type of client.DefaultRequestHeaders
(HttpRequestHeaders
) has no setters.
How do I create an array of headers and pass them to the client like this:
using (HttpClient client = new HttpClient(handler) { BaseAddress = baseAddress })
{
client.DefaultRequestHeaders = someVariable;
EDIT: I get it that the Authorization would be a different type, but I'm hoping there is a container for this, and other types of headers.