简体   繁体   English

在前端获取 http 请求标头

[英]Getting the http request headers in the frontend

I would like to see the http request headers in the frontend.我想在前端看到 http 请求标头。 I've been digging around in the browser's window object and saw the following:我一直在浏览器的 window object 中挖掘并看到以下内容:

new window.Response().headers.values()

I am aware that I can see the request headers on the backend server and then just send it as a response to the frontend, but I don't want to make the extra call instead I want to use the window object or something similar.我知道我可以在后端服务器上看到请求标头,然后将其作为对前端的响应发送,但我不想进行额外的调用,而是我想使用 window object 或类似的东西。 Is such anything possible?这样的事有可能吗?

You can get response headers like this.您可以获得这样的响应标头。 The Headers class instance that fetch returns is an iterable . fetch 返回的Headers class 实例是一个可迭代的。

 fetch('https://api.sampleapis.com/wines/reds').then(function(response) { response.headers.forEach(console.log); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM