title: How to Post JSON data to a Web API using HttpClient
body: <p>I have the following code, basically it takes in a dynamic object (in this case of type file) and using the <code>HTTPClient</code> class tries to a POST to a <code>WebAPI controller</code>, the issue I am having is that the controller is always getting <code>NULL</code> for the values on my <code>[FromBody]</code> parameter.</p>
  
  <h1>Code</h1>
  
  <pre><code>var obj = new
          {
              f = new File
              {
                  Description = description,
                  File64 = Convert.ToBase64String(fileContent),
                  FileName = fileName,
                  VersionName = versionName,
                  MimeType = mimeType
              },
          }
  
  var client = new HttpClient(signingHandler)
  {
     BaseAddress = new Uri(baseURL + path) //In this case v1/document/checkin/12345
  };
  
  client.DefaultRequestHeaders.Accept.Clear();
  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));                        
  
  HttpResponseMessage response;
  action = Uri.EscapeUriString(action);
  
  //Obj is passed into this, currently it is of type File 
  var content = new StringContent(JsonConvert.SerializeObject(obj).ToString(),
              Encoding.UTF8, "application/json");
  
  response = client.PostAsync(action, content)).Result;
  if (response.IsSuccessStatusCode)
  {     
      var responseContent = response.Content;                
      string responseString = responseContent.ReadAsStringAsync().Result;
      return JsonConvert.DeserializeObject&lt;T&gt;(responseString);
  }
  </code></pre>
  
  <h1>Controller</h1>
  
  <pre><code>[HttpPost]
  [Route("v1/document/checkin/{id:int}")]
  public void Checkin_V1(int id, [FromBody] File f)
  {
          //DO STUFF - f has null on all of its properties
  }
  </code></pre>
  
  <h1>Model</h1>
  
  <pre><code>public class File
  {
      public string FileName { get; set; }
      public string VersionName { get; set; }
      public string Description { get; set; }
      public string MimeType { get; set; }
      public byte[] Bytes { get; set;}
      public string File64 { get; set; }
  }
  </code></pre>
  
  <p>The model is shared on both the <code>WebAPI</code> and the client app.</p>
  
  <p>Any help on why this is failing would be much appreciated, been going around in circles for a while now.</p>