HowTo - Customize HTTP Headers in AJAX Request

Edit on GitHub

The XMLHttpRequest method setRequestHeader() sets the value of an HTTP request header. When using setRequestHeader(), you must call it after calling open(), but before calling send(). If this method is called several times with the same header, the values are merged into a single request header.

To update ajax-provider.ts for adding custom headers, add this.headers.forEach((value: string, key: string) => this.xhr.setRequestHeader(key, value)); into Promise of thefetch method.

Usage example:

this.ajaxProvider.headers.set(‘Accept’, ‘application/json’ );.