JQuery Ajax 请求:更改用户代理 [英] JQuery Ajax Request: Change User-Agent
问题描述
我正在使用 JQuery 向我自己的 Web 服务发出 AJAX 请求.我需要为 HTTP-AJAX-Request 设置或修改 User-Agent
HTTP-Header,我该如何最简单地做到这一点?
I'm using JQuery to issue an 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
方法来设置User-Agent
,但这不起作用.它实际上适用于其他新创建的标头(如 X-Test-Header
),但不适用于 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
.
推荐答案
这根本不可能,您不能更改 XMLHttpRequests 的用户代理.我不确定这对 Internet-Explorer 是否有效,但 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(header, 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屋!