Java Http Proxy
How to use the
jakarta.apache.org/commons/httpclientApache Commons HttpClient[/link] with an NTLM proxy (f**king M$)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
// begin NTLM proxy configuration
try {
HttpClient client = new HttpClient();
String proxyAddress = "<proxy_ip>"; // eg "10.0.0.254" or "proxy"
int proxyPort = <port>; // eg 8080
String userName = "<valid_user_name>";
String userPassword = "<valid_password>";
String userDomain = "<valid_domain>";
client.getHostConfiguration().setProxy( proxyAddress, proxyPort );
Credentials creds = null;
if ( userDomain == null ) {
creds = new UsernamePasswordCredentials( userName, userPassword );
} else {
creds = new NTCredentials( userName, userPassword, Inet4Address.getLocalHost().getHostName(), userDomain );
}
if ( creds != null ) {
client.getState().setProxyCredentials( proxyAddress, null, creds );
}
}
catch (UnknownHostException e) {
//TODO insert error handling of your choice here
e.printStackTrace();
}
// end NTLM proxy configuration