title: how to properly perform HTTP Post of a JSON object using C# HttpClient?
body: <p>I have a very simple C# Http Client console app, which needs to do an HTTP POST of a json object to a WebAPI v2.
  Currently, My app can do the POST using FormUrlEncodedContent:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Net.Http;
  using System.Net.Http.Headers;
  using Newtonsoft.Json;
  using System.Net.Http.Formatting;
  
  
  namespace Client1
  {
      class Program
      {
          class Product
          {
              public string Name { get; set; }
              public double Price { get; set; }
              public string Category { get; set; }
          }
          static void Main(string[] args)
          {
               RunAsync().Wait();
          }
          static async Task RunAsync()
          {
              using (var client = new HttpClient())
              {
                  client.BaseAddress = new Uri("http://localhost:8888/");
                  client.DefaultRequestHeaders.Accept.Clear();
                  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
                  var content = new FormUrlEncodedContent(new[] 
                          {
                              new KeyValuePair&lt;string, string&gt;("Category", "value-1"),
                              new KeyValuePair&lt;string, string&gt;("Name", "value-2")                           
                         });
  
                  var result = client.PostAsync("Incident", content).Result;      
                  var r = result;     
              }
          }
      }
  }
  </code></pre>
  
  <p>However, when I try to use JSON in the POST body, I get error 415 - Unsupported media Type:</p>
  
  <pre><code>class Product
  {
      public string Name { get; set; }
      public double Price { get; set; }
      public string Category { get; set; }
  }
  
  var gizmo = new Product() { Name = "Gizmo", Price = 100, Category = "Widget" };
  var  response = await client.PostAsJsonAsync("api/products", gizmo);
  </code></pre>
  
  <p>Doing explicit JSON serialization does not change the outcome for me:</p>
  
  <pre><code>string json = JsonConvert.SerializeObject(product);
  var  response = await client.PostAsJsonAsync("api/products", json);
  </code></pre>
  
  <p>What is the proper way to handle this, and to be able to POST JSON?</p>