title: How to use HttpClient to Post with Authentication
body: <p>I am trying to do the following curl (which works for me) in C# using HttpClient.</p>
  
  <pre><code>curl -X POST http://www.somehosturl.com \
       -u &lt;client-id&gt;:&lt;client-secret&gt; \
       -d 'grant_type=password' \
       -d 'username=&lt;email&gt;' \
       -d 'password=&lt;password&gt;' \
       -d 'scope=all
  </code></pre>
  
  <p>The C# Code:</p>
  
  <pre><code>HttpClientHandler handler = new HttpClientHandler { Credentials = new  
              System.Net.NetworkCredential ("my_client_id", "my_client_secret")
      };
  
  
      try
      {
          using(var httpClient = new HttpClient(handler))
          {
              var activationUrl = "www.somehosturl.com";
  
              var postData = "grant_type=password&amp;username=myemail@myemail.com&amp;password=mypass&amp;scope=all";
              var content = new StringContent(postData, Encoding.UTF8, "application/x-www-form-urlencoded");
  
              var response = await httpClient.PostAsync(activationUrl, content);
              if(!response.IsSuccessStatusCode)
                  return null;
  
              var result = await response.Content.ReadAsStringAsync();
  
              return result;
          }
      }
      catch(Exception)
      {
          return null;
      }
  </code></pre>
  
  <p>When executed, just crashes out, doesnt even catch the exception</p>
  
  <p>Normally I am able to GET and POST perfectly fine, but whats throwing me off is how to set the auth stuff (client-id and client-secret)</p>