@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(); }
/** * 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_; }
/** * 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_; }
/** * 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_; }
final CredentialsProvider credentialsProvider = webClient_.getCredentialsProvider();
final CredentialsProvider credentialsProvider = webClient_.getCredentialsProvider();
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()));