I get results from third-party REST services in my application. These services are stopped. Request header field X-XSRF-TOKEN is not allowed by Access-Control-Allow-Headers in preflight response.
because angular2 set this header as the standard for all requests by default.
I figured out how to disable this:
import { HttpModule, XSRFStrategy } from '@angular/http'; export class NoXSRFStrategy { configureRequest(req: Request) {
But this works at the module level, that is, it disables it for all requests, regardless of which service provides them.
What I would like is to decide for myself which Http call should be devoid of such headers and which can continue to use them. In the solution above, I have to isolate the service in a separate module and use NoXSRFStrategy
only for this module. I have not tested this with other services in other modules, but I hope this does not set NoXSRFStrategy
as the global request configuration.
Just to illustrate what I would like to be possible:
@Injectable() export class MyService { constructor(private http: Http) { } apiCall() { return this.http.get('some.online/service.json', {useXsrf: false});
Or perhaps at the service level:
@Injectable() export class MyService { constructor(private http: Http) { this.http.setXsrfStrategy(NoXSRFStrategy);
Does anyone know if there is a way to disable the X-XSRF-TOKEN header, besides setting the module level configuration?
source share