使用字符串参数调用HTTPPOST请求

时间:2017-08-11 01:51:15

标签: json asp.net-web-api http-post httpclient webapi2

我有一个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找不到错误, 我想我调用HTTPPOST的方式有问题。 有人可以帮帮我吗?

0 个答案:

没有答案