0

I have this angularjs service:

function checkCredentials(username,password) {
    return $http.post(config.baseUrl + "api/login/", username, password)
}

And this web api:

public class LoginController : ApiController
{
    private MorenoContext _context;

    public LoginController()
    {
        _context = new MorenoContext();
    }

    [HttpPost]
    public async Task<IHttpActionResult> Post(string username, string password)
    {
        return Ok("test");
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            _context.Dispose();
        }
        base.Dispose(disposing);
    }
}

But when try to call web api method with help of checkCredentials() client function I get this error:

Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/myProjectName/api/login/

Any idea why I get the error?

Michael
  • 13,950
  • 57
  • 145
  • 288
  • With web api post your parameters as an object OR individual parameters using query string. `return $http.post(config.baseUrl + "api/login/?username="+username+"&password="+ password)` – Igor Sep 20 '16 at 17:41
  • Possible duplicate of [Simple post to Web Api](http://stackoverflow.com/questions/19093603/simple-post-to-web-api) – Igor Sep 20 '16 at 17:44

0 Answers0