How to add Header values to HttpWebRequest in .Net Core
<p>I am developing simple Http client to consume an Asp.Net Core Web API. I want to pass few http header values to the Web API via HttpHeaderCollection. In previous versions of .Net framework allowed to add header values to the HttpHeaderCollection as following</p>

<pre><code>WebHeaderCollection aPIHeaderValues = new    WebHeaderCollection();           
aPIHeaderValues .Add("UserName","somevalue");
aPIHeaderValues .Add("TokenValue", "somevalue");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.add(aPIHeaderValues);
HttpWebResponse response = (HttpWebResponse)_request.GetResponse();
</code></pre>

<p>But in .Net Core there is no way to add headers to <strong>request.Headers</strong> collection. As well as we cannot add headers by defining new WebHeaderCollection </p>

<pre><code>WebHeaderCollection aPIHeaderValues = new    WebHeaderCollection();
</code></pre>

<p>Is there any alternative way to do this in .Net Core</p>