July 2018
Intermediate to advanced
354 pages
8h 51m
English
Headers can be added either in the constructor or via the append method. The following example uses the Headers constructor:
var httpHeaders = {
'Content-Type' : 'image/jpeg',
'Accept-Charset' : 'utf-8',
'X-My-Custom-Header' : 'custom-value'
};
var myHeaders = new Headers(httpHeaders);
Headers can also be added using the append method:
var myHeaders = new Headers();
myHeaders.append('Content-Type', 'image/jpeg');
myHeaders.append('Accept-Charset', 'utf-8);
myHeaders.append('X-My-Custom-Header', 'custom-value');
A final way to add headers is by using the set method:
var myHeaders = new Headers(); myHeaders.set('Content-Type', 'image/jpeg'); myHeaders.set('Accept-Charset', 'utf-8); myHeaders.set('X-My-Custom-Header', 'custom-value'); ...Read now
Unlock full access