com.gargoylesoftware.htmlunit.WebClient.getCredentialsProvider()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(149)

本文整理了Java中com.gargoylesoftware.htmlunit.WebClient.getCredentialsProvider()方法的一些代码示例,展示了WebClient.getCredentialsProvider()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.getCredentialsProvider()方法的具体详情如下:
包路径:com.gargoylesoftware.htmlunit.WebClient
类名称:WebClient
方法名:getCredentialsProvider

WebClient.getCredentialsProvider介绍

[英]Returns the credentials provider for this client instance. By default, this method returns an instance of DefaultCredentialsProvider.
[中]返回此客户端实例的凭据提供程序。默认情况下,此方法返回DefaultCredentialsProvider的实例。

代码示例

代码示例来源:origin: stackoverflow.com

@Test
public void homePage_proxy() throws Exception {
  final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_2, "http://myproxyserver", myProxyPort);

  //set proxy username and password 
  final DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider) webClient.getCredentialsProvider();
  credentialsProvider.addProxyCredentials("username", "password");

  final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
  assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText());

  webClient.closeAllWindows();
}

代码示例来源:origin: org.jvnet.hudson/htmlunit

/**
 * Lazily initializes the internal HTTP client.
 * @return the initialized HTTP client
 */
protected synchronized HttpClient getHttpClient() {
  if (httpClient_ == null) {
    httpClient_ = createHttpClient();
    // Disable informational messages from httpclient
    final Log log = LogFactory.getLog("httpclient.wire");
    if (log instanceof SimpleLog) {
      ((SimpleLog) log).setLevel(SimpleLog.LOG_LEVEL_WARN);
    }
    httpClient_.getHttpConnectionManager().getParams().setSoTimeout(getTimeout());
    httpClient_.getHttpConnectionManager().getParams().setConnectionTimeout(getTimeout());
    if (virtualHost_ != null) {
      httpClient_.getParams().setVirtualHost(virtualHost_);
    }
  }
  // Tell the client where to get its credentials from
  // (it may have changed on the webClient since last call to getHttpClientFor(...))
  httpClient_.getParams().setParameter(CredentialsProvider.PROVIDER, webClient_.getCredentialsProvider());
  return httpClient_;
}

代码示例来源:origin: net.disy.htmlunit/htmlunit

/**
 * Lazily initializes the internal HTTP client.
 * @return the initialized HTTP client
 */
protected synchronized HttpClient getHttpClient() {
  if (httpClient_ == null) {
    httpClient_ = createHttpClient();
    // Disable informational messages from httpclient
    final Log log = LogFactory.getLog("httpclient.wire");
    if (log instanceof SimpleLog) {
      ((SimpleLog) log).setLevel(SimpleLog.LOG_LEVEL_WARN);
    }
    httpClient_.getHttpConnectionManager().getParams().setSoTimeout(getTimeout());
    httpClient_.getHttpConnectionManager().getParams().setConnectionTimeout(getTimeout());
    if (virtualHost_ != null) {
      httpClient_.getParams().setVirtualHost(virtualHost_);
    }
  }
  // Tell the client where to get its credentials from
  // (it may have changed on the webClient since last call to getHttpClientFor(...))
  httpClient_.getParams().setParameter(CredentialsProvider.PROVIDER, webClient_.getCredentialsProvider());
  return httpClient_;
}

代码示例来源:origin: org.jenkins-ci/htmlunit

/**
 * Lazily initializes the internal HTTP client.
 * @return the initialized HTTP client
 */
protected synchronized HttpClient getHttpClient() {
  if (httpClient_ == null) {
    httpClient_ = createHttpClient();
    // Disable informational messages from httpclient
    final Log log = LogFactory.getLog("httpclient.wire");
    if (log instanceof SimpleLog) {
      ((SimpleLog) log).setLevel(SimpleLog.LOG_LEVEL_WARN);
    }
    httpClient_.getHttpConnectionManager().getParams().setSoTimeout(getTimeout());
    httpClient_.getHttpConnectionManager().getParams().setConnectionTimeout(getTimeout());
    if (virtualHost_ != null) {
      httpClient_.getParams().setVirtualHost(virtualHost_);
    }
  }
  // Tell the client where to get its credentials from
  // (it may have changed on the webClient since last call to getHttpClientFor(...))
  httpClient_.getParams().setParameter(CredentialsProvider.PROVIDER, webClient_.getCredentialsProvider());
  return httpClient_;
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

final CredentialsProvider credentialsProvider = webClient_.getCredentialsProvider();

代码示例来源:origin: HtmlUnit/htmlunit

final CredentialsProvider credentialsProvider = webClient_.getCredentialsProvider();

代码示例来源:origin: zidoshare/Elise

webClient = new WebClient(BrowserVersion.CHROME, proxy.getHost(), proxy.getPort());
if (!ValidateUtils.isEmpty(proxy.getUsername()) && !ValidateUtils.isEmpty(proxy.getPassword())) {
  webClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()));

相关文章

WebClient类方法