Skip to content

Instantly share code, notes, and snippets.

@mcrmfc
Created March 17, 2011 15:52
Show Gist options
  • Save mcrmfc/874572 to your computer and use it in GitHub Desktop.
Save mcrmfc/874572 to your computer and use it in GitHub Desktop.
HTMLUnit fix for proxy bypass
private static void setProxy(final HttpClient httpClient, final WebRequest webRequest) {
if (webRequest.getProxyHost() != null) {
final String proxyHost = webRequest.getProxyHost();
final int proxyPort = webRequest.getProxyPort();
final HttpHost proxy = new HttpHost(proxyHost, proxyPort);
if (webRequest.isSocksProxy()) {
final SocksSocketFactory factory = (SocksSocketFactory)
httpClient.getConnectionManager().getSchemeRegistry().getScheme("http").getSocketFactory();
factory.setSocksProxy(proxy);
}
else {
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
}
else {
httpClient.getParams().removeParameter(ConnRoutePNames.DEFAULT_PROXY);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment