Http POST is performing GET request

I’m trying make a request with POST method, but when I run this,

  login(username:string, password:string){
    let data = JSON.stringify({username:username,password:password});
    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({headers:headers,method:RequestMethod.Post});
    return this.http.post(APIHOST+'login', data,options)
      .map(res => res.json())
      .subscribe( data => {
        console.log("Success!: ", data);
      },err => {
        console.log("ERROR!: ", err);
      });
  }

Debug with Developer Tools

Request URL:https://truckfy.herokuapp.com/login/
Request Method:GET
Status Code:405 Method Not Allowed
Remote Address:75.101.162.66:443

Please why this is run with GET method ?

Hello, possibly your code is fine, except your post method

image

Test with a “/” at the end

this.http.post(APIHOST+‘login/’, data,options)

image

1 Like

Thank you! You save my whole day! lol :slight_smile:

1 Like