44import java .io .InputStream ;
55import java .io .InputStreamReader ;
66import java .io .OutputStream ;
7+ import java .net .Authenticator ;
78import java .net .HttpURLConnection ;
9+ import java .net .PasswordAuthentication ;
810import java .net .SocketTimeoutException ;
911import java .net .URL ;
1012import java .security .cert .CertificateException ;
@@ -96,6 +98,8 @@ private ResponseWrapper _sendRequest(String url, String content,
9698 conn = (HttpURLConnection ) aUrl .openConnection (_proxy .getNetProxy ());
9799 if (_proxy .isAuthenticationNeeded ()) {
98100 conn .setRequestProperty ("Proxy-Authorization" , _proxy .getProxyAuthorization ());
101+ Authenticator .setDefault (new SimpleProxyAuthenticator (
102+ _proxy .getUsername (), _proxy .getPassword ()));
99103 }
100104 } else {
101105 conn = (HttpURLConnection ) aUrl .openConnection ();
@@ -234,7 +238,7 @@ protected void initSSL() {
234238 }
235239
236240
237- public static class SimpleHostnameVerifier implements HostnameVerifier {
241+ private static class SimpleHostnameVerifier implements HostnameVerifier {
238242
239243 @ Override
240244 public boolean verify (String hostname , SSLSession session ) {
@@ -243,7 +247,7 @@ public boolean verify(String hostname, SSLSession session) {
243247
244248 }
245249
246- public static class SimpleTrustManager implements TrustManager , X509TrustManager {
250+ private static class SimpleTrustManager implements TrustManager , X509TrustManager {
247251
248252 @ Override
249253 public void checkClientTrusted (X509Certificate [] chain , String authType )
@@ -262,5 +266,20 @@ public X509Certificate[] getAcceptedIssuers() {
262266 return null ;
263267 }
264268 }
269+
270+ private static class SimpleProxyAuthenticator extends java .net .Authenticator {
271+ private String username ;
272+ private String password ;
265273
274+ public SimpleProxyAuthenticator (String username , String password ) {
275+ this .username = username ;
276+ this .password = password ;
277+ }
278+
279+ protected PasswordAuthentication getPasswordAuthentication () {
280+ return new PasswordAuthentication (
281+ this .username ,
282+ this .password .toCharArray ());
283+ }
284+ }
266285}
0 commit comments