title: C# Web API Sending Body Data in HTTP Post REST Client
body: <p>I need to send this HTTP Post Request:</p>
  
  <pre><code> POST https://webapi.com/baseurl/login
   Content-Type: application/json
  
   {"Password":"password",
   "AppVersion":"1",
   "AppComments":"",
   "UserName":"username",
   "AppKey":"dakey" 
    }
  </code></pre>
  
  <p>It works great in RestClient and PostMan just like above.</p>
  
  <p>I need to have this pro-grammatically and am not sure if to use </p>
  
  <p>WebClient, HTTPRequest or WebRequest to accomplish this.</p>
  
  <p>The problem is how to format the Body Content and send it above with the request.</p>
  
  <p>Here is where I am with example code for WebClient...</p>
  
  <pre><code>  private static void Main(string[] args)
      {
          RunPostAsync();
      } 
  
      static HttpClient client = new HttpClient();
  
      private static void RunPostAsync(){
  
              client.DefaultRequestHeaders.Accept.Clear();
              client.DefaultRequestHeaders.Accept.Add(
                  new MediaTypeWithQualityHeaderValue("application/json"));
  
              Inputs inputs = new Inputs();
  
              inputs.Password = "pw";
              inputs.AppVersion = "apv";
              inputs.AppComments = "apc";
              inputs.UserName = "user";
              inputs.AppKey = "apk";
  
  
              var res = client.PostAsync("https://baseuriplus", new StringContent(JsonConvert.SerializeObject(inputs)));
  
              try
              {
                  res.Result.EnsureSuccessStatusCode();
  
                  Console.WriteLine("Response " + res.Result.Content.ReadAsStringAsync().Result + Environment.NewLine);
  
              }
              catch (Exception ex)
              {
                  Console.WriteLine("Error " + res + " Error " + 
                  ex.ToString());
              }
  
          Console.WriteLine("Response: {0}", result);
      }       
  
      public class Inputs
      {
          public string Password;
          public string AppVersion;
          public string AppComments;
          public string UserName;
          public string AppKey;
      }
  </code></pre>
  
  <p>This DOES NOW WORK and responses with a (200) OK Server and Response</p>