title: Posting to a Web API using HttpClient and Web API method [FromBody] parameter ends up being null
body: <p>I am attempting to POST to a Web API using the HttpClient. When I put a breakpoint in the Save method of the Web API the [FromBody] Product is null. This means that something is wrong with the way I am posting the product over to the Web API. Can someone please take a look at the below code and see where I might be going wrong. I am assuming it is something to do with headers and content types.</p>
  
  <p><strong>POST call from a client repository to the Web API which should pass the product object through as JSON:</strong></p>
  
  <pre><code>public async Task&lt;Product&gt; SaveProduct(Product product)
  {
      using (var client = new HttpClient())
      {
          client.BaseAddress = new Uri("http://localhost:99999/");
          client.DefaultRequestHeaders.Accept.Clear();
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
          StringContent content = new StringContent(JsonConvert.SerializeObject(product));
          // HTTP POST
          HttpResponseMessage response = await client.PostAsync("api/products/save", content);
          if (response.IsSuccessStatusCode)
          {
              string data = await response.Content.ReadAsStringAsync();
              product = JsonConvert.DeserializeObject&lt;Product&gt;(data);
          }
      }
      return product;
  }
  </code></pre>
  
  <p><strong>Web API Controller Method:</strong></p>
  
  <pre><code>[HttpPost]
  [Route("save")]
  public IActionResult Save([FromBody]Product product)
  {
      if (customer == null)
      {
          return HttpBadRequest();
      }
      _manager.SaveCustomer(product);
      return CreatedAtRoute("Get", new { controller = "Product", id = product.Id }, product);
  }
  </code></pre>
  
  <p>[FromBody] Product product parameter ends up being null.</p>