title: Using Fiddler to send a POST request to WebApi
body: <p>I'm writing a simple WebApi program, using C#. (I know MVC fairly well, but I'm new to WebApi.) It contains a Vendors controller (VendorsController.cs), which contains a "getvendor" action as shown in the code sample below:</p>
  
  <pre><code>[RoutePrefix("api/vendors")]
  public class VendorsController : ApiController
  {
      [Route("getvendor"), HttpPost]
      public TAPUser GetVendor([FromBody] string username)
      {
          Int32 userid = -1;
  
      ...
  </code></pre>
  
  <p>The routes are configured as follows:</p>
  
  <pre><code>// Web API routes
  config.MapHttpAttributeRoutes();
  
  config.Routes.MapHttpRoute(
      name: "DefaultApi",
      routeTemplate: "api/{controller}/{id}",
      defaults: new { action = RouteParameter.Optional, id = RouteParameter.Optional
  );
  </code></pre>
  
  <p>I'm using Fiddler to test the program. First, I ran the above code without [FromBody] and used Fiddler to send a POST request with the username in the url like this:
      <a href="http://localhost:60060/api/vendors/getvendor?username=tapuser" rel="nofollow noreferrer">http://localhost:60060/api/vendors/getvendor?username=tapuser</a></p>
  
  <p>This worked fine. tapuser was passed as the argument to GetVendor and the action returned the expected result.</p>
  
  <p>Next, I added [FromBody] and put <code>username=tapuser</code> in the request body. This time, when I sent the request, <code>tapuser</code> did not get passed to the action. The argument to <code>GetVendor()</code> was <code>null</code>. I've tried variations on the request body such as <code>{ "username": "tapuser" }</code>, but it doesn't help. I've tried changing the route in various ways, too, such as changing <code>routeTemplate</code> to <code>"api/{controller}/{action}/{id}"</code>. That hasn't helped either. I'm sure I'm missing something very simple, but I just don't see it.</p>