ASP.NET API Controller返回XMLHttpRequest无法加载URL无效的HTTP状态代码404

时间:2015-07-06 19:04:33

标签: asp.net angularjs

这是控制器:

public class RECAPTCHAController : ApiController
    {
        [HttpPost]  
        public HttpResponseMessage Post(string response)
        {
            bool verified = Models.ReCaptcha.Verify(HttpContext.Current.Request);
            return this.Request.CreateResponse(HttpStatusCode.OK, new { verified = verified });      
        }
    }

我正在使用Angular来调用这个控制器:

$http.post(API_ENDPOINT + '/RECAPTCHA/Post', { response: vm.recaptcha }).
                              success(function (data, status, headers, config) {
                                  vm.captchaVerified = data.verified;
                              });

我收到以下错误:

{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:64189/api/RECAPTCHA/Post'.","MessageDetail":"No action was found on the controller 'RECAPTCHA' that matches the request."}

1 个答案:

答案 0 :(得分:0)

试试这个

$http.post(API_ENDPOINT + '/RECAPTCHA/', vm.recaptcha).
                          success(function (data, status, headers, config) {
                              vm.captchaVerified = data.verified;
                          });