Accessing the web page's HTTP Headers in JavaScript

前端 未结 17 2623
日久生厌
日久生厌 2020-11-21 04:53

How do I access a page\'s HTTP response headers via JavaScript?

Related to this question, which was modified to ask about accessing two specific HTTP headers.

<
17条回答
  •  迷失自我
    2020-11-21 05:50

    If we're talking about Request headers, you can create your own headers when doing XmlHttpRequests.

    var request = new XMLHttpRequest();
    request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    request.open("GET", path, true);
    request.send(null);
    

提交回复
热议问题