I currently am building out an Angular app that leverages Angular's httpClient to Post data to an api. The post works perfectly fine in other browsers besides IE11. When making the Post in IE11 I receive a 403, after doing some digging I found that IE11 is dropping my request headers which contains a required key for the API. If I refresh the page, the app will reload and make the API call just fine for some reason. In the code example below the "securityKey" key is whats being dropped.
I've tried adding other keys to see if it was just that specific key causing the issue but all keys appear be get dropped. Even the content type gets set dropped and set to text/plain.
return this.httpClient.post(
`${baseUrl}/test`,
request,
{
headers: {
'Content-Type': 'application/json',
'securityKey': 'foobar',
},
},
);
As in other browsers this code should make the post call with the defined request headers so that the security key gets sent.
UPDATE
My code has been updated to the following but now the x-api-key is not being set. This code resolved the fixed the fact that content-type was not being set correctly resulting the CORS like error. Now the issue is the header key for x-api-key is dropped or just not set. This only occurs on the first page load, after a refresh the header is set just fine.
public makeAPIcall(request) {
return this.httpClient.post(
`${baseUrl}/test`,
request,
{ headers: this.getHeaders() },
);
}
private getHeaders(): HttpHeaders {
const headers = new HttpHeaders();
headers.append('content-type', 'application/json');
headers.append('x-api-key', environment.key);
return headers;
}