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

2

5

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

xmlHttpRequest.setRequestHeader("User-Agent", "...");
Larger answered 9/8, 2011 at 11:17 Comment(3)
I hop that this wont work you shuld not be able to tell the server that your in an other env then you are from a client.Propaedeutic
You can and you should be able to tell the server that you're in a different enviroment than you actually are - and plenty of browsers do allow you o change your User-Agent string. That beeing said I do not know of such a mechanism controllable from JavaScript.Freethinker
On the client-side browser, I need to get the webpage source from a server that performs server-side browser sniffing. Any other ideas?Larger
J
4

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.

Johnathan answered 9/8, 2011 at 12:30 Comment(0)
E
5

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.

Egesta answered 9/8, 2011 at 11:25 Comment(0)
J
4

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.

Johnathan answered 9/8, 2011 at 12:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.