0

I have a POST request which have just a string parameter

  [HttpPost]
    public IHttpActionResult CheckMfaEnabled([FromBody]string userEmail)//
     {
         var isMfaEnabled = //use another service to return true/false
         return Ok(isMfaEnabled);
     }

and I call it like this

 using (var client = new HttpClient())
{
    client.BaseAddress = new Uri("http://localhost:60099");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    StringContent content = new StringContent(JsonConvert.SerializeObject(userEmail), Encoding.UTF8, "application/json");
                var response = client.PostAsync("api/MFA/CheckMfaEnabled", content).Result;
                return response.IsSuccessStatusCode;
}

It gets me 404 not found Error , I guess something is wrong in my way of calling HTTPPOST. Can anyone please help me?

Sara N
  • 1,079
  • 5
  • 17
  • 45

1 Answers1

0

This is a routing issue. When I modify your API method to use attribute routing by adding [Route("api/MFA/CheckMfaEnabled")] your client code works fine.

user2880616
  • 255
  • 3
  • 12