title: how to save an object using .net webapi
body: <p>I've create WebAPI in .net (my first). Using this api to get object from db, query db etc is easy for me. Nothing new</p>
  
  <p>But I'm wondering how to save an object using this webapi ? </p>
  
  <p>I have a clinet application (tablet, phone, PC) that communicates with my webapi. From my application there is an possibility to save a user news. Now I need to save it in db. I use Azure SQL. Now how can I pass this object to API so I can save it ?</p>
  
  <p>For my application I use C#/XAML
  For my WebAPI I use .NET</p>
  
  <p>I'm tring with this code:</p>
  
  <pre><code>HttpClient httpClient = new HttpClient();
          String u = this.apiUrl + "sd/Localization/insert";
          Uri uri = new Uri(u);
          HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, uri);
  </code></pre>
  
  <p>But I don't know how to send object ? Should I serialize it ? If yes how to send it via post.</p>
  
  <p>// UPDATE</p>
  
  <p>I've constructed this</p>
  
  <pre><code>        HttpClient httpClient = new HttpClient();
          String u = this.apiUrl + "sd/Localization/insert";
          Uri uri = new Uri(u);
          HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, uri);
          httpRequestMessage.Content = new StringContent("{'Name':'Foo', 'Surname':'Bar'}");
          await httpClient.PostAsync(uri, httpRequestMessage.Content);
  </code></pre>
  
  <p>But in my API the variable is null</p>
  
  <p>This is code from my api</p>
  
  <pre><code>    // POST sd/Localization/insert
      public void Post(string test)
      {
          Console.WriteLine(test);
      }
  </code></pre>
  
  <p>The "test" variable is null.
  What am I doing wrong ?</p>
  
  <p>// UPDATE 2</p>
  
  <pre><code>        using (HttpClient httpClient = new HttpClient())
          {
              String u = this.apiUrl + "sd/Localization/insert";
              Uri uri = new Uri(u);
              HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri)
              {
                  Method = HttpMethod.Post,
                  Content = new StringContent("my own test string")
              };
  
              await httpClient.PostAsync(uri, request.Content);
          }
  </code></pre>
  
  <p>Routing config</p>
  
  <pre><code>public class RouteConfig
  {
      public static void RegisterRoutes(RouteCollection routes)
      {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
          routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "sd/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
          );
  
          routes.MapRoute(
              name: "Default",
              url: "{controller}/{action}/{id}",
              defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
          );
      }
  }
  </code></pre>
  
  <p>after all your answers I've created this but still I get null on param in my api. Where is the mistake ?</p>