Modify Java SWT Browser User-agent
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 sp开发者_运维问答ecifying the user agent?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").
See: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fbrowser%2FBrowser.html
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
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.
精彩评论