main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var headers = new Headers();
headers.append('a', '1');
headers.append('b', '2');
var request = new Request('https://httpbin.org/get', {
        headers: headers
    });
for (var k of request.headers.keys()) {
    console.log('request.headers.get("' + k + '") =', request.headers.get(k));
}
fetch(request)
    .then(function(response) {
        for (var k of response.headers.keys()) {
            console.log('response.headers.get("' + k + '") =', response.headers.get(k));
        }
        return response.text();
    })
    .then(function(data) {
        console.log('data = ', data);
    })
    .catch(function(err) {
        console.error(err);
    });
Native Browser JavaScript