gpt4 book ai didi

javascript - XMLHttpRequest 未发送 'Via'

转载 作者:行者123 更新时间:2023-12-03 12:45:37 25 4
gpt4 key购买 nike

这是我的问题:使用 XMLHttpRequest 执行 AJAX 调用时它不会将“Via” header 添加到请求中。

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.poodle.com/", true);
...
xhr.setRequestHeader("Via", "Hello World");
...
xhr.send(null);

这是映射的信息:

(Request-Line)  GET / HTTP/1.1
Host poodle.com:80
User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0
Accept text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
Accept-Language null
Accept-Encoding gzip, deflate
Content-Type application/json
Referer http://www.poodle.com/
Cookie JSESSIONID=AB35C81E78FCE769187A8FD4611C3DD7
Connection keep-alive

但是当我使用它时,它可以工作,但我无法在真实的网页中使用它(仅限 Firefox Addon)。

var xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);

知道为什么吗?

最佳答案

W3C XHR spec 明确禁止在 JavaScript 中设置 Via header :

Terminate these steps if header is a case-insensitive match for one of the following headers:

  • Accept-Charset
  • Accept-Encoding
  • ...
  • Upgrade
  • User-Agent
  • Via

Note: The above headers are controlled by the user agent to let it control those aspects of transport. This guarantees data integrity to some extent.

关于javascript - XMLHttpRequest 未发送 'Via',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23354345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com