Created
March 17, 2011 15:52
-
-
Save mcrmfc/874572 to your computer and use it in GitHub Desktop.
HTMLUnit fix for proxy bypass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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