When should we use headers in the HttpRequestMessage object over headers in the HttpClient ??
We have need to add Authorization (always changing) and few custom headers (always changing )
Questions
- Which is the preferred method ?
Should i be adding common headers (same across all the requests) to the HttpClient and request based headers to the HttpRequestMessage object ??
//HttpRequestMessage Code HttpRequestMessage reqmsg =new HttpRequestMessage(); reqmsg.Headers.Authorization =new AuthenticationHeaderValue("some scheme"); reqmsg.Headers.Add("name","value"); //HttpClient Code HttpClient client =new HttpClient(); client.DefaultRequestHeaders.Authorization =new AuthenticationHeaderValue("some scheme"); client.DefaultRequestHeaders.Add("name", "value");