How can I spoof the user agent of a JavaScript GET request?

不羁岁月 提交于 2019-12-06 03:51:07

问题


How can I spoof the user agent of a JavaScript GET request? setRequestHeader with User-Agent isn't allowed:

xmlHttpRequest.setRequestHeader("User-Agent", "...");

回答1:


You can't do this in a half-decent browser because of security issues surrounding it. You don't want XSS scripts to be changing request headers and running rampant on your site.

However I believe there's a workaround in IE if you use VBScript:

MyHttp.setRequestHeader "User-Agent", "MyCustomUser"

The alternative is to have a web page on your site dedicated to forwarding a GET request, changing the appropriate headers as necessary.




回答2:


In short: You can't due to built-in cross-domain limitations.

One way "around" that was to write a proxy-webservice and let the server spoof whatever headers you need spoofed.



来源:https://stackoverflow.com/questions/6995311/how-can-i-spoof-the-user-agent-of-a-javascript-get-request

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