StatusCode: 400, ReasonPhrase: 'Bad Request' on web api call with object as parameter

-- -- 872 Reputation points
2022-06-09T13:33:25.96+00:00

Hi

I have a web api method that accepts an object as parameter;

[HttpPost]  
public bool InsertApplicant(Applicants applicant)  
{  
  // ...  
}  

I am consuming it using below code and I am getting 'StatusCode: 400, ReasonPhrase: 'Bad Request''.

using (var client = new HttpClient())  
{  
   client.BaseAddress = new Uri("http://example.com/api/InsertApplicant");  
  
   var postTask = client.PostAsJsonAsync<Applicants>("InsertApplicant", applicant);  
  
   postTask.Wait();  
  
   var result = postTask.Result;  
   // Getting StatusCode: 400, ReasonPhrase: 'Bad Request'  
}  

What am I doing wrong?

Thanks

Regards

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,165 questions
{count} votes