如何使用 javascript 从浏览器获取 HTTP_ACCEPT 标头?
是否可以仅使用 javascript 来接受 HTTP 标头?我知道使用 PHP 我会做类似 $_SERVER['HTTP_ACCEPT']
的事情,但据我所知 javascript 没有这个。
也许我可以用 XmlHttpRequest 做点什么?
任何帮助都会很棒!
谢谢,
麦克风
Is it possible HTTP Accept headers using only javascript? I know using PHP I would do something like this $_SERVER['HTTP_ACCEPT']
, but as far as I can tell javascript doesn't have this.
Perhaps I could do something with an XmlHttpRequest?
Any help would be awesome!
Thanks,
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
RE:“发送到服务器的标头。”
您可以在服务器的响应中回显它们,并以这种方式获取它们。
IE。)在网页上,您可以使用该值创建一个隐藏的表单字段,或者将值弹出到从页面发出的 javascript 中。
在 Web 服务中,您可以将传入标头的值包含在传出 XML 或 JSON 的一部分中。
如果您使用的是 XmlHttpRequest,则可以使用此值将标头返回发送到客户端。
可能性是无限的。
我怀疑为什么这会有用。客户在提出请求之前应该知道自己期望什么。
RE: "The headers sent to the server."
You could echo them back out in the server's response, and get them that way.
IE.) On a web-page you could make a hidden form field with the value, or pop the value into the javascript that gets emited from the page.
From a web service, you could include the value of the incoming header in part of the outgoing XML or JSON.
If you're using XmlHttpRequest, you could send a header back to the client with this value.
Possibilities are endless.
I'm dubious of why this would ever be useful though. The client should know what it's expecting before it requests it.
您正在寻找从服务器发送的标头还是发送到的标头?
如果您使用 Firefox 并且想要查看或更改从浏览器到服务器的标头,您可以查看 修改标题插件的来源。它不是纯粹的 javascript,但它可能有助于松动一些东西。
Are you looking for headers sent from the server or to?
If you're using Firefox and want to look at or alter headers going from the browser to the server, you might look at the sources for the Modify Headers plugin. It's not pure javascript, but it may help shake something loose.