title: Web API HttpClient PutAsync returning Http 404
body: <p>Im trying to send a PUT to my Web API and am struggling a bit as to how I should construct the actual Http request. Below is an integration test sample. It works fine using HttpMessageInvoker to call the Web API Put, but I want to use HttpClient in test also since that is what I'll be using in the business layer.</p>
  
  <pre><code>    [TestMethod]
      public void Verify_UpdateBudgetData_Http_PUT()
      {
          int budgetId = 1;
          string appId = "DummyApp";
          string userId = "Dummy";
          string value = "400";
          string filterJSON =
                  "{dimensionFilter:{\"Demo_Konto\":[\"3000\"],\"Demo_AO\":[\"200\"]},valueSpreadType:{\"Value1\":0}}";
  
          HttpConfiguration config = new HttpConfiguration();
          Konstrukt.SL.AggregationEngine.WebApiConfig.Register(config, new SL.AggregationEngine.AutofacStandardModule());
          HttpServer server = new HttpServer(config);
  
          /*this works*/
          using (HttpMessageInvoker client = new HttpMessageInvoker(server))
          {
              using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, 
                  String.Format("http://localhost/AggregationEngine/UpdateBudgetData/{0}/{1}/{2}/{3}/{4}",
                  budgetId, appId, userId, value, filterJSON)))
              using (HttpResponseMessage response = client.SendAsync(request, CancellationToken.None).Result)
              {
                  Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Wrong http status returned");
              }
          };
  
          /*this does not work*/
          using (var client = new HttpClient())
          {
              //client.BaseAddress = new Uri("http://localhost");
              client.DefaultRequestHeaders.Accept.Clear();
              client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
              var responseMessage =
                  client.PutAsync(
                      String.Format("http://localhost/AggregationEngine/UpdateBudgetData/{0}/{1}/{2}/{3}/{4}",
                          budgetId, appId, userId, value, filterJSON), new StringContent("")).Result;
              Assert.AreEqual(HttpStatusCode.OK, responseMessage.StatusCode, "Wrong http status returned");
          }
      }
  </code></pre>
  
  <p>Here is my WebApiConfig-class</p>
  
  <pre><code>public static class WebApiConfig
  {
      public static void Register(HttpConfiguration config, Autofac.Module moduleToAppend)
      {
          config.Routes.MapHttpRoute(
              name: "UpdateBudgetData",
              routeTemplate: "AggregationEngine/{controller}/{budgetId}/{appId}/{userId}/{value}/{filterJSON}",
              defaults: new { filter = RouteParameter.Optional }
          );
  
          config.Routes.MapHttpRoute(
              name: "GetBudgetAndRefData",
              routeTemplate: "AggregationEngine/{controller}/{budgetId}/{userId}/{filterJSON}",
              defaults: new { filter = RouteParameter.Optional }
          );
  
          config.EnableCors();
          config.EnableSystemDiagnosticsTracing();
  
          // Autofac container
          // if not configured here you'll not have dependencies provided to your WebApiControllers when called
          var builder = new ContainerBuilder(); // yes, it is a different container here
  
          builder.RegisterAssemblyTypes( // register Web API Controllers
              Assembly.GetExecutingAssembly())
                  .Where(t =&gt;
                      !t.IsAbstract &amp;&amp; typeof(ApiController).IsAssignableFrom(t))
                  .InstancePerLifetimeScope();
  
          // register your graph - shared
          builder.RegisterModule(
              new AutofacStandardModule()); // same as with ASP.NET MVC Controllers
  
          if (moduleToAppend != null)
          {
              builder.RegisterModule(moduleToAppend);
          }
  
          var container = builder.Build();
  
          config.DependencyResolver = new AutofacWebApiDependencyResolver(
              container);
      }
  
      public static void Register(HttpConfiguration config)
      {
          Register(config, null);
      }
  }
  </code></pre>
  
  <p>How can I fix the HttpClient call to PutAsync? Should I embed the FilterJSON parameter in the body? If so, how to do that? I've tried that but then the FromBody parametger was null...</p>