How do I set a default Header for all XMLHTTPRequests

后端 未结 1 1489
庸人自扰
庸人自扰 2021-01-22 10:00

Problem description

We are running a Kibana 4.3 service. I do not want to modify the source code.

The objective is add an encrypted token, call

1条回答
  •  别那么骄傲
    2021-01-22 10:26

    I was searching for solution for this problem as well but couldn't find anything and then I came up with next solution:

            XMLHttpRequest.prototype.origOpen = XMLHttpRequest.prototype.open;
            XMLHttpRequest.prototype.open   = function () {
                this.origOpen.apply(this, arguments);
                this.setRequestHeader('X-TOKEN', 'the token');
            };

    0 讨论(0)
提交回复
热议问题