Customizing HTTP headers in AJAX requests

Edit on GitHub

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

To add custom headers to ajax-provider.ts, add this.headers.forEach((value: string, key: string) => this.xhr.setRequestHeader(key, value)); into the promise of the fetch method.

Example:

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