title: API POST call from Console Application
body: <p>How to do the REST API POST Call from the console Application ?</p>
  
  <p>I want to pass the class from the Console application to the REST API. My below code is working if I have to do the GET call but not for the POST. It is hitting the API but in the Parameter it is not passing anything.</p>
  
  <p>API</p>
  
  <pre><code>public class Student
  {
      public int Id { get; set; }
      public string Name { get; set; }
  }
  public class ValuesController : ApiController
  {
      // GET api/values
      public IEnumerable&lt;string&gt; Get()
      {
          return new string[] { "value1", "value2" };
      }
  
      // GET api/values/5
      public string Get(int id)
      {
          return "value";
      }
  
      // POST api/values
  
      //public void Post([FromBody]string value)
      //{
  
      //}
      public void Post([FromBody]Student value)
      {
  
      }
  
  
  
  }
  </code></pre>
  
  <p>Console Application</p>
  
  <pre><code> static async Task CallWebAPIAsync()
      {
  
          var student = new Student() { Id = 1, Name = "Steve" };
  
          using (var client = new HttpClient())
          {
              //Send HTTP requests from here. 
              client.BaseAddress = new Uri("http://localhost:58847/");
                client.DefaultRequestHeaders.Accept.Clear();
              client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
  
              HttpResponseMessage response = await client.PostAsJsonAsync("api/values", student);
              if (response.IsSuccessStatusCode)
              {
  
              }
              else
              {
                  Console.WriteLine("Internal server Error");
              }
          }
      }
  </code></pre>
  
  <p>The Same is working if I call from fiddler.</p>
  
  <p>User-Agent: Fiddler
  Content-Length: 31
  Host: localhost:58847
  Content-Type: application/json</p>
  
  <p>Request Body:
  {
  "Id":"1",
  "Name":"Rohit"
  }</p>