JQuery Ajax Request: Change User-Agent

℡╲_俬逩灬. 提交于 2019-11-26 15:29:18

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:

The setRequestHeader() method

[...]

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:

[...]

  • User-Agent

If you are using jQuery, set the request header in the ajaxSetup.

$.ajaxSetup({
  beforeSend: function(request) {
    request.setRequestHeader("User-Agent","InsertUserAgentStringHere");
  }
});

Well, you could always use jQuery to post to a server-side page which then in turn is able to modify the User-Agent header, and also make a request to the page which would have been directly accessed by jQuery.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!