title: How to properly add HttpRequestHeaders using system.net.http library
body: <p>I created a HttpRequestMessage with header using <strong>windows.web.http;</strong> library:</p>
  
  <pre><code>var request = base.CreateHttpRequestMessage();
          request.Headers.Add("SESSION", SessionId);
          return request;
  </code></pre>
  
  <p>and after sending SendRequestAsync(); , I am able to get the response successfully .</p>
  
  <p>But in my case I need to use <strong>system.net.http;</strong> library, with same codes:</p>
  
  <pre><code>var request = base.CreateHttpRequestMessage();
          request.Headers.Add("SESSION", SessionId);
          return request;
  </code></pre>
  
  <p>but when I am calling the SendAsync(); , I am getting an UnAuthorized response.
  Does anyone knows what causing the issue?</p>
  
  <pre><code>var source = new CancellationTokenSource(timeout)
  var response = await _client.SendAsync(request, source.Token)
                      .ConfigureAwait(false);
  </code></pre>
  
  <p><strong>NOTE:</strong> I tried manually setting same valid <strong>SessionId</strong> for both , on <strong>windows.web.http</strong> its Okay, but on <strong>system.net.http</strong> its unauthorized.</p>
  
  <p>How I initialize my HttpClient:</p>
  
  <pre><code>private HttpClientHandler handler;
  handler = new HttpClientHandler();
  
  private HttpClient _client;
  _client = new HttpClient(handler)
  </code></pre>
  
  <p><strong>Reference Link:</strong> <a href="https://docs.microsoft.com/en-us/dotnet/api/system.net.http?view=netframework-4.7.2" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/api/system.net.http?view=netframework-4.7.2</a> <br>
  <a href="https://docs.microsoft.com/en-us/uwp/api/windows.web.http" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/uwp/api/windows.web.http</a></p>
  
  <p><strong>Requests Header format:</strong><br>
  windows.web.http:
  <a href="https://i.stack.imgur.com/O2fKc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O2fKc.jpg" alt="enter image description here"></a>
  system.net.http:
  <a href="https://i.stack.imgur.com/2F0Mv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2F0Mv.jpg" alt="enter image description here"></a></p>
  
  <p>Thanks.</p>