I have a REST-API to contact, it works on swagger. Now I try to call it with my Angular 4 app. I get the error:
XMLHttpRequest cannot load
"baseURL"/company/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access
When I look at the call, I see that it doesn't pass any headers (also not the token), but I actually added them to my request in my Angular 4 code:
getCompanies(): Observable<Company[]> {
let tokenobject =JSON.parse(sessionStorage.getItem('current_user'));
let token = tokenobject.token;
let headers = new Headers({ 'Access-Control-Allow-Origin' : 'http://localhost:4200','Authorization': token });
let options = new RequestOptions({ headers: headers });
return this.http.get(this.url + this.path, options)
.map(this.extractData)
.catch(this.handleError);
}
Is there something I forgot or did wrong?