IE 接受标题更改,为什么?
我正在尝试调试服务器端的问题,我相信这与从浏览器发送的接受标头有关。我的问题是,为什么 Internet Explorer 会将“接受”标头从一个页面更改为另一个页面?我可以从 JavaScript 更改请求标头吗?
这是来自一个页面的请求:
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-application, application/x-shockwave-flash, */*
这是来自另一页面的请求:
Accept: */*
它们都是 GET 请求,我看到内容之间有任何重大差异。所有服务均由同一应用程序服务器 (Websphere) 提供。
I am trying to debug an issue on my server side and I believe it has to do with the accept headers that are being sent from the browser. Here is my question, why would Internet Explorer change "accept" headers from one page to another page? Can I change the request headers from javascript?
Here is a request from one page:
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-application, application/x-shockwave-flash, */*
Here is a request from another page:
Accept: */*
They are all GET requests and I see any major differences between the content. All served from the same application server (Websphere).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IE 的 Accept headers
根据 此博客来自 IE 开发人员的帖子,IE 与其 Accept 标头“不一致”。它解释了您看到的额外值来自应用程序可以添加其内容类型的注册表项,但没有解释为什么不总是使用此注册表项中的值:
知道这一点可能并不能真正解决您的问题。但请注意,
*/*
仍然出现在两个 Accept 标头中,因此就内容协商而言,这里应该没有问题。但是,添加到标头的额外类型可能会使请求太大,因此这可能会为您提供从哪里开始查找的线索。使用 JavaScript 修改请求标头
您可以使用
XMLHttpRequest.setRequestHeader()
方法修改异步 (XMLHttpRequest) 请求的标头,如 此页面。另请参阅此问题:使用 JavaScript 添加自定义 HTTP 标头
免责声明:我没有尝试将其用于接受标头。
但是,如果您想要控制的请求不是 AJAX 请求,我不知道您可以使用 JavaScript 修改这些请求。
很抱歉,我无法对您的两个问题提供完整的答案,但希望我提供的信息对您有所帮助。
IE's Accept headers
According to this blog post from an IE developer, IE is "inconsistent" with its Accept headers. It explains that the extra values you see come from a registry key to which which applications can add their content types, but does not explain why the values from this registry key are not always used:
Knowing this probably doesn't really solve your problem. But notice that
*/*
still occurs in both Accept headers, so as far as content negotiation is concerned there should be no problem here. However, the extra types added to the header could be making the request too large, so that might give you a clue about where to start looking.Modifying request headers with JavaScript
You can modify the headers of asynchronous (XMLHttpRequest) requests using
XMLHttpRequest.setRequestHeader()
method, described on this page.Also see this question: Adding custom HTTP headers using JavaScript
Disclaimer: I have not tried using this for Accept headers.
If the requests you want to control are not AJAX requests, however, I'm not aware of any way you can modify these with JavaScript.
Sorry that I've not been able to provide complete answers to both of your questions, but I hope the information I've given is helpful.