title: How do I pass an object to HttpClient.PostAsync and serialize as a JSON body?
body: <p>I'm using <code>System.Net.Http</code>, I found several examples on the web. I managed to create this code for make a <code>POST</code> request:</p>
  
  <pre><code>public static string POST(string resource, string token)
  {
      using (var client = new HttpClient())
      {
          client.BaseAddress = new Uri(baseUri);
          client.DefaultRequestHeaders.Add("token", token);
  
          var content = new FormUrlEncodedContent(new[]
          {
               new KeyValuePair&lt;string, string&gt;("", "")
          });
  
          var result = client.PostAsync("", content).Result;
          string resultContent = result.Content.ReadAsStringAsync().Result;
          return resultContent;
      }
   }
  </code></pre>
  
  <p>all working fine. But suppose that I want pass a third param to the <code>POST</code> method, a param called <code>data</code>. The data param is an object like this:</p>
  
  <pre><code>object data = new
  {
      name = "Foo",
      category = "article"
  };
  </code></pre>
  
  <p>how can I do that without create the <code>KeyValuePair</code>? My php <code>RestAPI</code> wait a json input, so the <code>FormUrlEncodedContent</code> should send the <code>raw</code> json correctly. But how can I do this with <code>Microsoft.Net.Http</code>? Thanks.</p>