JS 获取HTTP请求头的信息

代码:

var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
alert(headers);

 

示例图:

 

 

获取某一属性的值:

var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
alert(req.getResponseHeader('date'))

 

示例图:

 

posted @ 2020-06-05 16:11  _whys  阅读(9422)  评论(1编辑  收藏  举报