Reading response headers with Fetch API

后端 未结 6 1629
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 06:54

    From MDN

    You can also get all the headers by accessing the entries Iterator.

    // Display the key/value pairs
    for (var pair of res.headers.entries()) {
       console.log(pair[0]+ ': '+ pair[1]);
    }
    

    Also, keep in mind this part:

    For security reasons, some headers can only be controlled by the user agent. These headers include the forbidden header names and forbidden response header names.

提交回复
热议问题