public static void setProxyAuthenticator ( final String proxyHost , final String proxyPort , final String proxyUser , final String decodedPwd ) { if ( proxyUser == null || proxyUser . isEmpty ( ) || decodedPwd == null || decodedPwd . isEmpty ( ) ) { return ; } //Authenticate proxy credentials Authenticator . setDefault ( new Authenticator ( ) { @ Override public PasswordAuthentication getPasswordAuthentication ( ) { if ( getRequestorType ( ) == RequestorType . PROXY ) { if ( getRequestingHost ( ) . equals ( proxyHost ) && getRequestingPort ( ) == Integer . valueOf ( proxyPort ) ) { return new PasswordAuthentication ( proxyUser , decodedPwd . toCharArray ( ) ) ; } } return null ; } } ) ; }
Set Proxy Authenticator Default