简体   繁体   English

修改Java SWT浏览器用户代理

[英]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.

相关问题 谁能帮助您以编程方式使用Selenium Webdriver将修改标头用户代理添加到Chrome浏览器 - Can anyone help to how to add modify header user-agent to chrome browser using selenium webdriver programmatically 在Java中更改Google IAM的User-Agent - Change User-Agent for Google IAM in Java 如何使用Java中的Web-Harvest库输出浏览器用户代理字符串 - How to output the browser User-Agent String using Web-Harvest library in Java 尽管设置了User-Agent,但来自Java应用程序的HTTP 403(但不是Web浏览器) - HTTP 403 from Java app (but not web browser), despite User-Agent set 在GWT中基于浏览器用户代理更改UiTemplate - Change UiTemplate based on browser user-agent in GWT HttpServletRequest#getHeader(“User-Agent”) 返回空浏览器名称 - HttpServletRequest#getHeader(“User-Agent”) returns null browser name 为什么我不能设置Java http User-Agent? - Why can't I set Java http User-Agent? 如何防止用户更改用户代理 - How to prevent user-agent to be changed by user Appengine欺骗用户代理字符串 - Appengine spoof User-Agent string 过滤器之前的资源中没有用户代理(getAgent) - No user-agent (getAgent) in filter preceding resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM