0

我有一个 POST 请求,它只有一个字符串参数

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

我这样称呼它

 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;
}

它让我404 not found Error,我猜我调用 HTTPPOST 的方式有问题。谁能帮帮我吗?

4

1 回答 1

0

这是一个路由问题。当我通过添加您的客户端代码来修改您的 API 方法以使用属性路由时,[Route("api/MFA/CheckMfaEnabled")]效果很好。

于 2017-08-12T15:02:01.390 回答