0

In postman, I have:

POST:    https://myapp.herokuapp.com/login
BODY:     {"email": "myemail@gmail.com", "password": "123456"}

and it works.

In provider, I have:

public login(credentials): Observable<any> {
    const httpOptions = {
      headers: new HttpHeaders({
        'Content-Type':  'application/json'
      })};

    return this.http.post(API_URL + '/login', {params: {email: credentials.email, password: credentials.password}}, httpOptions);
  }

I get Not Found error. In console in Network tab, request method is OPTIONS. What is wrong?

EDIT: I get following error:

enter image description here

1 Answers1

0

try without params:

public login(credentials): Observable<any> {
    const httpOptions = {
        headers: new HttpHeaders({
            'Content-Type':  'application/json'
        })
    };

    return this.http.post(API_URL + '/login', {email: credentials.email, password: credentials.password}, httpOptions);
}

If this doesn't work then this may be occurring due to CORS requests, this is something called Preflighted request. Browser always sends the OPTIONS request to server when you invoke CORS requests to know what methods are actually allowed.

See more:

Abdul Rafay
  • 2,793
  • 2
  • 21
  • 40