Java: process http.proxyUser and http.proxyPassword
Friday, 20 April 2012
Some tutorials suggest to use the system properties http.proxyUser and http.proxyPassword to get proxy authentication, but that won't work since - in contrast to http.proxyHost and http.proxyPort - these properties will not be processed by Java's HttpURLConnection.
Other suggest to use a custom default Authenticator. But that's dangerous because this would send your password to anybody who asks.
The following snippet contains some code that uses an Authenticator to process http.proxyUser, but ensures that these information will be sent to the host that is defined by http.proxyHost:
// Java ignores http.proxyUser. Here come's the workaround. @Override if (getRequestorType() == RequestorType.PROXY) { if (getRequestingHost().toLowerCase().equals(host.toLowerCase())) { // Seems to be OK. } } } return null; } });