本文整理汇总了Java中com.gargoylesoftware.htmlunit.WebClient.getOptions方法的典型用法代码示例。如果您正苦于以下问题:Java WebClient.getOptions方法的具体用法?Java WebClient.getOptions怎么用?Java WebClient.getOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.gargoylesoftware.htmlunit.WebClient
的用法示例。
在下文中一共展示了WebClient.getOptions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: helloWebClient
import com.gargoylesoftware.htmlunit.WebClient; //导入方法依赖的package包/类
public static void helloWebClient(WebClient client, WebClient jsclient) {
final BrowserVersion browser = client.getBrowserVersion();
System.out.println("ApplicationName: " + browser.getApplicationName());
System.out.println("ApplicationCodeName: " + browser.getApplicationCodeName());
System.out.println("ApplicationVersion: " + browser.getApplicationVersion());
System.out.println("ApplicationMinorVersion: " + browser.getApplicationMinorVersion());
System.out.println("BrowserLanguage: " + browser.getBrowserLanguage());
System.out.println("BuildId: " + browser.getBuildId());
System.out.println("CpuClass: " + browser.getCpuClass());
System.out.println("CssAcceptHeader: " + browser.getCssAcceptHeader());
System.out.println("HtmlAcceptHeader: " + browser.getHtmlAcceptHeader());
System.out.println("ImgAcceptHeader: " + browser.getImgAcceptHeader());
System.out.println("Nickname: " + browser.getNickname());
System.out.println("Platform: " + browser.getPlatform());
System.out.println("ScriptAcceptHeader: " + browser.getScriptAcceptHeader());
System.out.println("SystemLanguage: " + browser.getSystemLanguage());
System.out.println("UserAgent: " + browser.getUserAgent());
System.out.println("UserLanguage: " + browser.getUserLanguage());
System.out.println("Vendor: " + browser.getVendor());
System.out.println("XmlHttpRequestAcceptHeader: " + browser.getXmlHttpRequestAcceptHeader());
final int n = browser.getPlugins().size();
int i = 0;
System.out.println("Plugins(" + n + "):");
for (PluginConfiguration pc : browser.getPlugins()) {
i++;
System.out.println(String.format(
" name=%s\n version=%s\n description=%s\n filename=%s\n mime-types=%s",
pc.getName(),
pc.getVersion(),
pc.getDescription(),
pc.getFilename(),
Arrays.toString(pc.getMimeTypes().toArray())
));
if (i < n) {
System.out.println(" --");
}
}
final WebClientOptions clientOptions = client.getOptions();
System.out.println("Timeout: " + clientOptions.getTimeout());
System.out.println("MaxInMemory: " + clientOptions.getMaxInMemory());
System.out.println("HistorySizeLimit: " + clientOptions.getHistorySizeLimit());
System.out.println("HistoryPageCacheLimit: " + clientOptions.getHistoryPageCacheLimit());
System.out.println("isActiveXNative: " + clientOptions.isActiveXNative());
System.out.println("isAppletEnabled: " + clientOptions.isAppletEnabled());
System.out.println("isCssEnabled: " + clientOptions.isCssEnabled());
System.out.println("isDoNotTrackEnabled: " + clientOptions.isDoNotTrackEnabled());
System.out.println("isDownloadImages: " + clientOptions.isDownloadImages());
System.out.println("isGeolocationEnabled: " + clientOptions.isGeolocationEnabled());
System.out.println(String.format(
"isJavaScriptEnabled: %b | %b",
clientOptions.isJavaScriptEnabled(),
jsclient.getOptions().isJavaScriptEnabled()
));
System.out.println("isPopupBlockerEnabled: " + clientOptions.isPopupBlockerEnabled());
System.out.println("isRedirectEnabled: " + clientOptions.isRedirectEnabled());
System.out.println("isThrowExceptionOnFailingStatusCode: " + clientOptions.isThrowExceptionOnFailingStatusCode());
System.out.println("isThrowExceptionOnScriptError: " + clientOptions.isThrowExceptionOnScriptError());
System.out.println("isUseInsecureSSL: " + clientOptions.isUseInsecureSSL());
System.out.print("\n");
}
示例2: LinkedInOAuthRequestFilter
import com.gargoylesoftware.htmlunit.WebClient; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public LinkedInOAuthRequestFilter(OAuthParams oAuthParams, Map<String, Object> httpParams,
boolean lazyAuth, String[] enabledProtocols) {
this.oAuthParams = oAuthParams;
this.oAuthToken = null;
// create HtmlUnit client
webClient = new WebClient(BrowserVersion.FIREFOX_38);
final WebClientOptions options = webClient.getOptions();
options.setRedirectEnabled(true);
options.setJavaScriptEnabled(false);
options.setThrowExceptionOnFailingStatusCode(true);
options.setThrowExceptionOnScriptError(true);
options.setPrintContentOnFailingStatusCode(LOG.isDebugEnabled());
options.setSSLClientProtocols(enabledProtocols);
// add HTTP proxy if set
if (httpParams != null && httpParams.get(ConnRoutePNames.DEFAULT_PROXY) != null) {
final HttpHost proxyHost = (HttpHost) httpParams.get(ConnRoutePNames.DEFAULT_PROXY);
final Boolean socksProxy = (Boolean) httpParams.get("http.route.socks-proxy");
final ProxyConfig proxyConfig = new ProxyConfig(proxyHost.getHostName(), proxyHost.getPort(),
socksProxy != null ? socksProxy : false);
options.setProxyConfig(proxyConfig);
}
// disable default gzip compression, as error pages are sent with no compression and htmlunit doesn't negotiate
new WebConnectionWrapper(webClient) {
@Override
public WebResponse getResponse(WebRequest request) throws IOException {
request.setAdditionalHeader(HttpHeaders.ACCEPT_ENCODING, "identity");
return super.getResponse(request);
}
};
if (!lazyAuth) {
try {
updateOAuthToken();
} catch (IOException e) {
throw new IllegalArgumentException(
String.format("Error authorizing user %s: %s", oAuthParams.getUserName(), e.getMessage()), e);
}
}
}