title: How to use System.Net.HttpClient to post a complex type?
body: <p>I have a custom complex type that I want to work with using Web API.</p>
  
  <pre><code>public class Widget
  {
      public int ID { get; set; }
      public string Name { get; set; }
      public decimal Price { get; set; }
  }
  </code></pre>
  
  <p>And here is my web API controller method. I want to post this object like so:</p>
  
  <pre><code>public class TestController : ApiController
  {
      // POST /api/test
      public HttpResponseMessage&lt;Widget&gt; Post(Widget widget)
      {
          widget.ID = 1; // hardcoded for now. TODO: Save to db and return newly created ID
  
          var response = new HttpResponseMessage&lt;Widget&gt;(widget, HttpStatusCode.Created);
          response.Headers.Location = new Uri(Request.RequestUri, "/api/test/" + widget.ID.ToString());
          return response;
      }
  }
  </code></pre>
  
  <p>And now I'd like to use <code>System.Net.HttpClient</code> to make the call to the method. However, I'm unsure of what type of object to pass into the <code>PostAsync</code> method, and how to construct it. Here is some sample client code. </p>
  
  <pre><code>var client = new HttpClient();
  HttpContent content = new StringContent("???"); // how do I construct the Widget to post?
  client.PostAsync("http://localhost:44268/api/test", content).ContinueWith(
      (postTask) =&gt;
      {
          postTask.Result.EnsureSuccessStatusCode();
      });
  </code></pre>
  
  <p>How do I create the <code>HttpContent</code> object in a way that web API will understand it?</p>