How to use token in ionic 2

Here is my error after executing this code

 getSecret() {
   var token='06a92668-966c-4ac0-9566-830c34720150';
      let header = new Headers();
      header.append('Authorization', 'Bearer ' + token);
 this.http.get(`http://localhost:9090/rest/branches/`,{headers: header}).map(res => res.json())
          data => this.branche = data,
          err => err


(index):1 XMLHttpRequest cannot load http://localhost:9090/rest/branches/. Response for preflight has invalid HTTP status code 401

It’s a CORS issue. Does it work on a real device with a real URL?

yes with rest client

You already posted the exact same thing in another topic, so I am a bit pissed that you ignore all the responses there and just reposted here…

2 ways to solve this:

  1. Add a service proxy if you are using ionic serve
  2. Or just fix the damn backend to respond with something else than “Status Code 401” to OPTIONS requests to this URL

No other way to fix it.

1 Like

Ok thanks do not get annoyed
how to add proxy scroll down to “Service Proxies”.

OK thank you I keep you up to date