Good morning, I need to connect to a service that requires authentication by passing some headers, most of all ways I tried, does not send my custom header, here is the code below:
public listarCategorias(): Observable<category[]> {
return this.http.get<category[]>('https://xxxxx/categories')
.pipe(
tap(heroes => { this.log('listarCategorias') }),
catchError(this.handleError('listarCategorias', []))
);
}
I made an Interceptor
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'x-accountmanager-key': 'xxxx',
'x-api-key': 'xxxx',
'x-user-email': 'xxxx',
}
const clone = req.clone({
setHeaders: headers
});
return next.handle(clone);
}
I tested it in several applications like ARC, and authenticate it normally.
The Header I captured in the browser was as follows:
: method: OPTIONS: path: / categories: scheme: https accept: / accept-encoding: gzip, deflate, br accept-language: pt-BR, pt; q = 0.9, en-US; q = 0.8, en; q = 0.7 access-control-request-headers: content-type, x-accountmanager-key, x-api-key, x-user-email access-control-request-method: GET origin: link user-agent: Mozilla / 5.0 (Windows NT 10.0, Win64, x64) AppleWebKit / 537.36 (KHTML, like Gecko) Chrome / 62.0.3202.94 Safari / 537.36
Arnaldo R. Portela, I changed his example, and it was not, when I run in ARC, it goes