[英]Modify Java SWT Browser User-agent
How is it possible to set the user agent header sent by SWT Browser? 如何设置SWT浏览器发送的用户代理标头?
edit: Or is there any browser lib for java that allows specifying the user agent? 编辑:或者是否有Java的浏览器库允许指定用户代理?
According to the SWT platform documentation, you can specify user headers including user-agent: 根据SWT平台文档,您可以指定用户标头,包括用户代理:
public boolean setUrl(String url,
String postData,
String[] headers)
Begins loading a URL. 开始加载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. 如果URL导致发起HTTP请求,则将随请求一起发送提供的postData和标头参数(如果有)。 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").
headers参数中的值必须是带有冒号分隔符的名称/值对,才能发送(例如:“ 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 请参阅: 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. 不是GUI浏览器,但是Jakarta Commons HttpClient允许您指定用户代理。
http://www.manticmoo.com/articles/jeff/programming/java/setting-user-agent-in-jakarta-httpclient.php 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? 您可以代替使用以下Swing浏览器组件的堆栈溢出问题列表: 最佳Java / Swing浏览器组件?
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. 它们中的许多都是开源的,并且用Java编写,因此您可以选择其中之一,并在所选组件的源代码中更改用户代理标头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.