Search code examples
angularangular4-httpclient

angular 2/4: 405 (Method Not Allowed)


Inside my logincomponent

    this.authenticationService.login('user', 'password').subscribe(comments => {
        alert('success');
    });

Inside my AuthService:

login(username: string, password: string) {
      let headers = new Headers({ 'Content-Type': 'application/json' });
        let options = new RequestOptions({ headers: headers });
        let url = 'http://22.5.66.58/api/v1/Identity/Login';
        console.log(this.data);
        return this.http.post(url, this.data, options).map((res: Response) => res.json());

}

Solution

  • It looks like your api route doesn't allow POST method, but maybe only GET or PUT. You have to fix on the API (server) side.