@Injectable()
export class TokenInterceptorService implements HttpInterceptor {
constructor(private injector: Injector) {
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const authReq = req.clone({
headers: req.headers.set('Authorization', "dassda")
});
console.log(authReq);
return next.handle(authReq);
}
}
any tutorials on Internet use this code to add Authorization header in a request, in my situation if I set header, all other headers are deleted.
Error : "Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource".
but if I delete line headers: req.headers.set('Authorization', "dassda")
always is ok
console.log(req.headers)
returns map(0)
I'm trying:
hardcode all headers- error anywhere
trying to use all methods in req.headers like append, setHeaders, Headers
append headers like "Access-Control-Allow-Origin/headers/methods" and etc -create new headers,
download google plugin Moesif Origin & CORS Changer that program add all needed headers to all requests- then write error "has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status."