How is it possible to set the user agent header sent by SWT Browser?
edit: Or is there any browser lib for java that allows specifying the user agent?

- 6,567
- 18
- 58
- 85
3 Answers
According to the SWT platform documentation, you can specify user headers including user-agent:
public boolean setUrl(String url,
String postData,
String[] headers)
Begins loading a URL. The loading of its content occurs asynchronously.
If the URL causes an HTTP request to be initiated then the provided postData and header arguments, if any, are sent with the request. A value in the headers argument must be a name-value pair with a colon separator in order to be sent (for example: "user-agent: custom").

- 229
- 5
- 5
Not a GUI browser, but Jakarta Commons HttpClient allows you to specify the user-agent.
http://www.manticmoo.com/articles/jeff/programming/java/setting-user-agent-in-jakarta-httpclient.php

- 15,812
- 8
- 39
- 47
-
It would be OK if it accepted cookies automatically for each site. – user Sep 07 '10 at 13:56
This Stack Overflow question lists of browser components for Swing that you could use instead: Best Java/Swing browser component?
A number of them are open source and written in Java, so you could pick one of those and change the user agent header in the source code of your chosen component.