title: How do I send an HTTP POST with HTTP Basic Authorization in ASP.NET Core?
body: <p>I'm trying to use the Reddit API (<a href="https://github.com/reddit-archive/reddit/wiki/OAuth2" rel="nofollow noreferrer">https://github.com/reddit-archive/reddit/wiki/OAuth2</a>) in my ASP.NET Core MVC app, and to obtain a token I have to make a POST to a URI with HTTP Basic Authorization (username and password being a client id and secret). Currently I use this code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public async Task&lt;HttpResponseMessage&gt; HttpPost(string uri, string value)
  {
      HttpClient httpClient = new HttpClient();
      HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(uri, new StringContent(value));
      return httpResponseMessage;
  }
  </code></pre>
  
  <p>However, this doesn't use the authorization. How can I add authorization? I tried looking at the documentation for <code>HttpClient.PostAsync</code> and <code>HttpContent</code>, but I don't see anything relevant.</p>