XP1
XP1

Reputation: 7183

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

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

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

Upvotes: 5

Views: 6494

Answers (2)

tskuzzy
tskuzzy

Reputation: 36476

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.

Upvotes: 4

erlando
erlando

Reputation: 6756

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.

Upvotes: 5

Related Questions