JQuery的AJAX请求:改变用户代理 [英] JQuery Ajax Request: Change User-Agent
问题描述
我使用jQuery发出AJAX请求到自己的web服务。我需要设置或修改用户代理
HTTP标头的HTTP-AJAX请求,我怎么能做到这一点的最简单的方法是什么?
I'm using JQuery to issue a AJAX-Request to my own Webservice. I need to set or modify the User-Agent
HTTP-Header for the HTTP-AJAX-Request, how can I do this the easiest way?
我想提供一些用户使用 setRequestHeader
方法来设置用户代理的提示,但不起作用。它在实际上工作等新创建的头文件(如 X-测试标头
),但它并不适用于工作的User-Agent
。
I tried the hint provided by some users to use the setRequestHeader
Method to set the User-Agent, but this does not work. It does in fact work for other newly created headers (like X-Test-Header
) but it does not work for User-Agent
.
谢谢!
推荐答案
这是根本不可能的,你不能改变用户代理的XMLHtt prequests。我不知道这是否是有效的互联网浏览器,但W3C指定这里:
It is simply impossible, you are not allowed to change the user-agent for XMLHttpRequests. I'm not sure if this is valid for Internet-Explorer, but the w3c specifies here:
在setRequestHeader()方法
The setRequestHeader() method
[...]
在调用setRequestHeader(头,value)方法,用户代理必须执行这些步骤: [...]
When the setRequestHeader(header, value) method is invoked, the user agent must run these steps: [...]
终止这些步骤,如果标题是不区分大小写的匹配以下标题之一:
Terminate these steps if header is a case-insensitive match for one of the following headers:
[...]
- 用户代理
这篇关于JQuery的AJAX请求:改变用户代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!