0

I'm getting Connection refused error when I'm using a proxy configuration in Android Studio and send a request to server.

Does anyone have a light about this?

This is my Client builder:

 SSLContext sslContext = SSLContext.getInstance("SSL");
 TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
 trustManagerFactory.init(keyStore);
 KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
 keyManagerFactory.init(keyStore, keyStorePass.toCharArray());
 sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());

 client = new OkHttpClient.Builder().sslSocketFactory(sslContext.getSocketFactory())
         .hostnameVerifier(new HostnameVerifier() {
             @Override
             public boolean verify(String s, SSLSession sslSession) {
                 return true;
             }
         }).connectTimeout(timeout, TimeUnit.MILLISECONDS)
         .readTimeout(timeout, TimeUnit.MILLISECONDS)
         .writeTimeout(timeout, TimeUnit.MILLISECONDS).build();

This is the Error log:

W/System.err: java.net.ConnectException: Failed to connect to /10.51.33.41:443
        at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:222)
W/System.err:     at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:146)
        at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:186)
        at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121)
        at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W/System.err:     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
        at okhttp3.RealCall.execute(RealCall.java:63)
W/System.err:     at br.com.oi.http.HttpClient.doRequest(HttpClient.java:192)
        at br.com.oi.http.HttpClient.doRequest(HttpClient.java:86)
        at br.com.oi.dadosfacil.service.oi.login.LoginService.run(LoginService.java:64)
        at br.com.oi.http.BaseService.onHandleIntent(BaseService.java:38)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:76)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:65)
    Caused by: java.net.ConnectException: failed to connect to /10.51.33.41 (port 443) from /192.163.222.2 (port 49536) after 120000ms: isConnected failed: ECONNREFUSED (Connection refused)
W/System.err:     at libcore.io.IoBridge.isConnected(IoBridge.java:273)
        at libcore.io.IoBridge.connectErrno(IoBridge.java:188)
        at libcore.io.IoBridge.connect(IoBridge.java:130)
        at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:129)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:356)
W/System.err:     at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:357)
W/System.err:     at java.net.Socket.connect(Socket.java:616)
        at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.java:63)
        at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:220)
        ... 25 more
W/System.err: Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
        at libcore.io.IoBridge.isConnected(IoBridge.java:262)
W/System.err:   ... 35 more

I'm using minSdkVersion 19 and targetSdkVersion 26

Victor Soares
  • 757
  • 1
  • 8
  • 34
  • Please provide the entire error log. – K_mns Nov 08 '20 at 23:57
  • Does this answer your question? [OkHTTPClient Proxy authentication how to?](https://stackoverflow.com/questions/35554380/okhttpclient-proxy-authentication-how-to) – K_mns Nov 09 '20 at 00:05
  • No this doesnt answer my question. I edited with the error log – Victor Soares Nov 09 '20 at 00:49
  • causedby : connect failed: ECONNREFUSED (Connection refused) it means nothing is listening to IP nor Port, first disable firewall and try also check your ip address via ipconfig/all, let me know if it worked or not ! – K_mns Nov 09 '20 at 01:16
  • There is nothing wrong with the IP or firewall as the problem only occurs when the proxy is configured. The connection works if I access without the proxy – Victor Soares Nov 09 '20 at 13:03

0 Answers0