Reading response headers with Fetch API

后端 未结 6 1632
Happy的楠姐
Happy的楠姐 2020-11-28 06:42

I\'m in a Google Chrome extension with permissions for \"*://*/*\" and I\'m trying to make the switch from XMLHttpRequest to the Fetch API.

The extensio

6条回答
  •  没有蜡笔的小新
    2020-11-28 07:14

    For backward compatibility with browsers that do not support ES2015 iterators (and probably also need fetch/Promise polyfills), the Headers.forEach function is the best option:

    r.headers.forEach(function(value, name) {
        console.log(name + ": " + value);
    });
    

    Tested in IE11 with Bluebird as Promise polyfill and whatwg-fetch as fetch polyfill. Headers.entries(), Headers.keys() and Headers.values() does not work.

提交回复
热议问题