title: Using PostAsync method from HttpClient Class with an API key in C#
body: <p>I would like to write the equivalent of this curl script in C#. My curl script is the following:</p>
  <pre><code>curl -X POST \
  https://example.com/login \
  -H 'api-key: 11111111' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
  &quot;username&quot;: &quot;myemail@hotmail.com,
  &quot;password&quot;: &quot;mypassword&quot;
  }'
  </code></pre>
  <p>The corresponding C# code I have wrote is the following:</p>
  <pre><code>async static void PostRequest()
  {
      string url=&quot;example.com/login&quot;
      var formData = new List&lt;KeyValuePair&lt;string, string&gt;&gt;();
      formData.Add(new KeyValuePair&lt;string, string&gt;(&quot;username&quot;, &quot;myemail@hotmail.com&quot;));
      formData.Add(new KeyValuePair&lt;string, string&gt;(&quot;password&quot;, &quot;mypassword&quot;));
      HttpContent q = new FormUrlEncodedContent(formData);
      // where do I put my api key?
      using (HttpClient client = new HttpClient())
      {
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(&quot;application/json&quot;));//ACCEPT header
          client.BaseAddress = new Uri(url);
          using (HttpResponseMessage response = await client.PostAsync(url, q))
          {
              using (HttpContent content =response.Content)
              {
                  string mycontent = await content.ReadAsStringAsync();              
              }        
          }
      }
  }
  </code></pre>
  <p>My question is how do I include the Api Key to my request?</p>