I am coding according to this guide: https://angular.io/guide/http#configuring-other-parts-of-the-request.
My code is the following:
loadMenuOptions(): void {
console.log('this.currentApiKey |' + this.currentApiKey);
let header = new HttpHeaders();
header = header.set('api-key', this.currentApiKey);
this.commonService. getMenuOptions(MENU_OPTIONS, header).subscribe(respuesta => this.setMenuOptions(respuesta));
}
The following code is when I send this object to the server:
getMenuOptions(endPoint: string, header: HttpHeaders): Observable<OptionsResponse> {
console.log('header:' + JSON.stringify(header));
return this.http.get<OptionsResponse>(endPoint, header)
.pipe(
tap(res => this.log('getMenuOptions | status | ' + res.header.status)),
catchError(this.handleError('getMenuOptions', null)));
}
JSON.stringify shows this value:
header:{"normalizedNames":[],"lazyUpdate":[{"name":"api-key","value":"JEFE_HHHABBBJJJXXX","op":"s"}],"headers":[],"lazyInit":{"normalizedNames":[],"lazyUpdate":null,"headers":[]}}
but the server is not receiving the 'api-key' value.
I executed POSTMAN with the same value and the server correctly received the 'api-key' value.
What am I doing wrong?
UPDATE
This snapshot represents the first time that is invoked the 'getMenuOptions' method: first call to the server
This screenshot belongs to the second call to the server:
As you are seeing at the 2nd part of the 2nd call, the header which contains the 'api-key' value is sent inside a 'lazyUpdate' object.