4

我正在尝试添加一个完全自定义的 HTTP 标头 - 在本例中作为示例 - 标头 = 狗,值 = 猫。当我运行它时,它没有获取新的标头,而是将 dog 附加到 access-control-request-headers 中的值?如何获得新的自定义标头?

代码:

            HR = new XMLHttpRequest();
            HR.onload = function (e) {
                    }
            HR.open("GET", URI);
            HR.setRequestHeader('dog', 'cat');
            HR.send();

通过 Chrome 开发者工具查看的请求标头:

access-control-request-headers: origin, dog
access-control-request-method: GET
origin: http://localhost:8888
accept-encoding: gzip,deflate,sdch
accept-language: en-US,en;q=0.8
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36
:path: /
accept: */*
:version: HTTP/1.1
cache-control: max-age=0
referer: http://localhost:8888/x.html
:scheme: https
:method: OPTIONS
Response Headersview source
access-control-allow-headers:origin, dog
access-control-allow-methods:OPTIONS
access-control-allow-origin:*
access-control-max-age:300
cache-control:private, no-cache, no-store, must-revalidate
content-length:0
4

0 回答 0