0

​Hello,

I have a problem with my HTTP requests. Is it possible please to help me understand what is happening?

When I am sending a GET request it is sent as OPTIONS:

let headers = new HttpHeaders();

headers = headers.set('Content-Type', 'application/json; charset=utf-8')
​.set('Authorization','bearer ' + this.auth.getUserToken());

 this.http.get(SERVER.URL_PROD + API.VERSION + API.GET_USERS, {headers: headers}).subscribe((res: any) => {
  console.log(res);
});

In my chrome dev tool debug I see the following:

Request Method: OPTIONS

Status Code: 405 Method Not Allowed
2

1 Answer 1

5

Like David said, you are experiencing a CORS issue. Specifically when you are on a browser, the browser sends an OPTIONS request to the api/backend to say hey can I get this before firing a GET. If the response to OPTIONS comes back as no you cannot, such as your 405 then you are prevented from doing a GET.

In order to fix this, the backend that you are hitting needs to implement CORS and allow the various HTTP METHODS that it supports.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your very clear and quick response. +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.