IE 接受标题更改,为什么?

发布于 2024-08-10 02:17:11 字数 545 浏览 3 评论 0原文

我正在尝试调试服务器端的问题,我相信这与从浏览器发送的接受标头有关。我的问题是,为什么 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

面犯桃花 2024-08-17 02:17:11

IE 的 Accept headers

根据 此博客来自 IE 开发人员的帖子,IE 与其 Accept 标头“不一致”。它解释了您看到的额外值来自应用程序可以添加其内容类型的注册表项,但没有解释为什么不总是使用此注册表项中的值:

但是,在某些导航中,您会看到 IE 发送更完整的字符串,其中包含各种 MIME 类型。例如:

图像/jpeg、应用程序/x-ms-application、图像/gif、应用程序/xaml+xml、图像/pjpeg、应用程序/x-ms-xbap、应用程序/msword、应用程序/vnd.ms- excel,应用程序/x-shockwave-flash,*/*

按 F5 刷新该页面,IE 可能会再次返回发送/。显然,IE 在 Accept 标头中选择发送的内容不一致,但现在您可能很好奇这些 MIME 类型从何而来。

IE 通过枚举以下注册表项中列出的值来生成此列表:

HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Accepted Documents

知道这一点可能并不能真正解决您的问题。但请注意,*/* 仍然出现在两个 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:

However, in some navigations, you’ll see that IE sends a more complete string, containing a wide variety of MIME-types. For instance:

image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/msword, application/vnd.ms-excel, application/x-shockwave-flash, */*

Hit F5 to refresh that page, and IE will probably go back to sending / again. Clearly, IE is inconsistent in what it chooses to send in the Accept header, but by now you’re probably curious where these MIME types even come from.

IE generates this list by enumerating the values listed in the following registry key:

HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Accepted Documents

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文