OkHttp fails to connect to ESP8266 - android

I'm trying to send a simple HTTP request to a ESP8266 from my Android phone. I'm following this tutorial. The code works for the URL used in the tutorial (https://reqres.in/api/users?page=2), however not for the URL that turns on the LED on ESP8266. (Turning on the LED is possible through a browser though, so it must be something with the code). The URL is https://192.168.137.78/led/1.
The stacktrace is quite long, but this is the first error,
2020-06-13 12:55:55.948 13594-13631/com.example.esp W/System.err: java.net.ConnectException: Failed to connect to /192.168.137.78:443
The rest of the stacktrace:
2020-06-13 12:55:55.948 13594-13631/com.example.esp W/System.err: java.net.ConnectException: Failed to connect to /192.168.137.78:443
2020-06-13 12:55:55.949 13594-13631/com.example.esp W/System.err: at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:285)
2020-06-13 12:55:55.949 13594-13631/com.example.esp W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:195)
2020-06-13 12:55:55.950 13594-13631/com.example.esp W/System.err: at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:249)
2020-06-13 12:55:55.950 13594-13631/com.example.esp W/System.err: at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:108)
2020-06-13 12:55:55.950 13594-13631/com.example.esp W/System.err: at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:76)
2020-06-13 12:55:55.951 13594-13631/com.example.esp W/System.err: at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:245)
2020-06-13 12:55:55.951 13594-13631/com.example.esp W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
2020-06-13 12:55:55.951 13594-13631/com.example.esp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
2020-06-13 12:55:55.951 13594-13631/com.example.esp W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:96)
2020-06-13 12:55:55.952 13594-13631/com.example.esp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
2020-06-13 12:55:55.952 13594-13631/com.example.esp W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
2020-06-13 12:55:55.952 13594-13631/com.example.esp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
2020-06-13 12:55:55.953 13594-13631/com.example.esp W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
2020-06-13 12:55:55.953 13594-13631/com.example.esp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
2020-06-13 12:55:55.953 13594-13631/com.example.esp W/System.err: at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:197)
2020-06-13 12:55:55.954 13594-13631/com.example.esp W/System.err: at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:502)
2020-06-13 12:55:55.954 13594-13631/com.example.esp W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2020-06-13 12:55:55.954 13594-13631/com.example.esp W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2020-06-13 12:55:55.955 13594-13631/com.example.esp W/System.err: at java.lang.Thread.run(Thread.java:919)
2020-06-13 12:55:55.956 13594-13631/com.example.esp W/System.err: Caused by: java.net.ConnectException: failed to connect to /192.168.137.78 (port 443) from /192.168.137.82 (port 42408) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
2020-06-13 12:55:55.956 13594-13631/com.example.esp W/System.err: at libcore.io.IoBridge.isConnected(IoBridge.java:288)
2020-06-13 12:55:55.957 13594-13631/com.example.esp W/System.err: at libcore.io.IoBridge.connectErrno(IoBridge.java:193)
2020-06-13 12:55:55.957 13594-13631/com.example.esp W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:135)
2020-06-13 12:55:55.957 13594-13631/com.example.esp W/System.err: at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:142)
2020-06-13 12:55:55.957 13594-13631/com.example.esp W/System.err: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
2020-06-13 12:55:55.958 13594-13631/com.example.esp W/System.err: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
2020-06-13 12:55:55.958 13594-13631/com.example.esp W/System.err: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
2020-06-13 12:55:55.959 13594-13631/com.example.esp W/System.err: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
2020-06-13 12:55:55.959 13594-13631/com.example.esp W/System.err: at java.net.Socket.connect(Socket.java:621)
2020-06-13 12:55:55.959 13594-13631/com.example.esp W/System.err: at okhttp3.internal.platform.Platform.connectSocket(Platform.kt:120)
2020-06-13 12:55:55.960 13594-13631/com.example.esp W/System.err: at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:283)
2020-06-13 12:55:55.960 13594-13631/com.example.esp W/System.err: ... 18 more
2020-06-13 12:55:55.961 13594-13631/com.example.esp W/System.err: Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
2020-06-13 12:55:55.961 13594-13631/com.example.esp W/System.err: at libcore.io.IoBridge.isConnected(IoBridge.java:275)
2020-06-13 12:55:55.961 13594-13631/com.example.esp W/System.err: ... 28 more

You're sending an HTTPS request, not an HTTP request. You haven't shared the code you're running on the ESP8266 but I'll bet that it's an HTTP server not an HTTPS server. Change the URL that you're trying to connect with to http:// instead of https://.

Related

How to get Android Studio to recognize DoD ssl certificates

I am trying to use a government api (https://api.usno.navy.mil/rstt/oneday?date=8/8/2019&coords=48.39,-115.56&tz=-7) to get sunrise and sunset type information and I get the error java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. I was having the same problems using the Chrome browser on Windows 10 until I imported the government certificates.
However, I can not figure out how to get the Android Studio emulator to recognize the certs (I will worry about my Nexus 6 device after I get everything working in the emulator).
I have a file of the government certs and have added them to Android Studio using Settings/tools/ServerCertificates. The certs I have added are DOD ID SW CA-38, DoD Root CA 2, DoD Root CA 3, and DoD Root CA 4. When I look at the certificate path on the browser, it shows DoD Root CA 3, DOD ID SW CA-38 and api.usno.navy.mil. The api.usno.navy.mil cert was issued by DOD ID SW CA-38.
I have tried setting the Server Certificates to "Accept non-trusted certificates automatically" (not my favorite option).
All were no help. I have also looked through the stackoverflow messages that seem related and did not find a solution. I am trying to not use third party apps.
Although it was not apparently needed in the browser, could there be some other certificate specifically for the api.usno.navy.mil reference?
The usno (U.S. Naval Observatory) has requested certificates that are more generally acknowledged (versus the DoD certificates), but they don't know when the administrators will provide them.
How can I get the Android Studio emulator to recognize these DoD certificates?
Any suggestions would be appreciated. Thanks.
Complete stack trace follows:
4424-4451/com.drme.weathertest W/System.err: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms#13280022#13.2.80 (040700-211705629):47)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:192)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:149)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:244)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(Unknown Source:0)
4424-4451/com.drme.weathertest W/System.err: at com.drme.weatherNoaa.NetworkHelpers.getUrlBytes(NetworkHelpers.java:123)
4424-4451/com.drme.weathertest W/System.err: at com.drme.weatherNoaa.SunMoonWebRunnable.run(SunMoonWebRunnable.java:108)
4424-4451/com.drme.weathertest W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
4424-4451/com.drme.weathertest W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
4424-4451/com.drme.weathertest W/System.err: at java.lang.Thread.run(Thread.java:764)
4424-4451/com.drme.weathertest W/System.err: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
4424-4451/com.drme.weathertest W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:646)
4424-4451/com.drme.weathertest W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:495)
4424-4451/com.drme.weathertest W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:418)
4424-4451/com.drme.weathertest W/System.err: at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:339)
4424-4451/com.drme.weathertest W/System.err: at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94)
4424-4451/com.drme.weathertest W/System.err: at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:88)
4424-4451/com.drme.weathertest W/System.err: at java.lang.reflect.Method.invoke(Native Method)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.Platform.checkTrusted(:com.google.android.gms#13280022#13.2.80 (040700-211705629):2)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.Platform.checkServerTrusted(:com.google.android.gms#13280022#13.2.80 (040700-211705629):1)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.verifyCertificateChain(:com.google.android.gms#13280022#13.2.80 (040700-211705629):5)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.NativeSsl.doHandshake(:com.google.android.gms#13280022#13.2.80 (040700-211705629):8)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms#13280022#13.2.80 (040700-211705629):15)
4424-4451/com.drme.weathertest W/System.err: ... 18 more

My Android app does not work on https call at First Run After Installation

My Android app does not work on https call at First Run After Installation.
And then restart app after https call is fine. Only First Run After Installation does not working.
My App use multiple network class Socket(for tcp/ip), Http wrapped class(HttpClient, HttpGet)
**Error Log -----------------------------------------------**
D/InputTransport: Input channel destroyed: fd=91
I/SemDesktopModeManager: unregisterListener: android.view.ViewRootImpl$3#b979a69
I/System.out: AsyncTask #2 calls detatch()
W/System.err: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:368)
W/System.err: at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:406)
W/System.err: at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:219)
W/System.err: at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:172)
W/System.err: at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:130)
W/System.err: at org.apache.http.impl.client.DefaultRequestDirector.executeOriginal(DefaultRequestDirector.java:1334)
W/System.err: at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:700)
W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:658)
W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:632)
W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:621)
W/System.err: at com.yuanta.mainlib.view.alarm.EventHttpProcessor$NoticeAsyncTask.doInBackground(EventHttpProcessor.java:63)
W/System.err: at com.yuanta.mainlib.view.alarm.EventHttpProcessor$NoticeAsyncTask.doInBackground(EventHttpProcessor.java:51)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:304)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err: at java.lang.Thread.run(Thread.java:762)
W/System.err: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path
W/System.err: at com.android.org.conscrypt.TrustManagerImpl.verifyChain(TrustManagerImpl.java:546)
W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:427)
W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:491)
W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:491)
W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:387)
W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:361)
W/System.err: at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:290)
W/System.err: at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94)
W/System.err: at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:88)
W/System.err: at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:178)
W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:617)
W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:364)
W/System.err: ... 18 more
W/System.err: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
W/System.err: ... 31 more
I/System.out: Thread-2620(ApacheHTTPLog):isSBSettingEnabled false
I/System.out: Thread-2620(ApacheHTTPLog):isShipBuild true
I/System.out: Thread-2620(ApacheHTTPLog):getDebugLevel 0x4f4c
I/System.out: Thread-2620(ApacheHTTPLog):Smart Bonding Setting is false
Did you add these in your manifest?
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Android Studio Emulator Cannot connect to Internet behind Proxy Server in Linux

I'm having trouble connecting Android studio emulator to Internet behind proxy.
I have enabled permission in android Manifest.xml
<uses-permission android:name="android.permission.INTERNET" />
And the app works perfectly well in USB Debug mode.
This is the error i get when i run the app on Emulator.
Following is my Logcat .
D/makeGitHubSearchQuery: Inside Function
D/makeGitHubSearchQuery: HTTP
D/makeGitHubSearchQuery: https://api.github.com/search/repositories?q=HTTP&sort=stars
D/OnOptionsItemSelected: action_search
W/System.err: java.net.UnknownHostException: Unable to resolve host "api.github.com": No address associated with hostname
W/System.err: at java.net.InetAddress.lookupHostByName(InetAddress.java:470)
W/System.err: at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
W/System.err: at java.net.InetAddress.getAllByName(InetAddress.java:215)
W/System.err: at com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
W/System.err: at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:188)
W/System.err: at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:157)
W/System.err: at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:100)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:357)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:340)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:433)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:384)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:231)
W/System.err: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
W/System.err: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
W/System.err: at com.example.android.datafrominternet.utilities.NetworkUtils.getResponseFromHttpUrl(NetworkUtils.java:76)
W/System.err: at com.example.android.datafrominternet.MainActivity$GithubQueryTask.doInBackground(MainActivity.java:77)
W/System.err: at com.example.android.datafrominternet.MainActivity$GithubQueryTask.doInBackground(MainActivity.java:71)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err: at java.lang.Thread.run(Thread.java:818)
W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
W/System.err: at libcore.io.Posix.android_getaddrinfo(Native Method)
W/System.err: at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
W/System.err: at java.net.InetAddress.lookupHostByName(InetAddress.java:451)
Please guide me in setting the Proxy settings in Android emulator.
Use this command to open emulator with the desired proxy.
emulator -avd [emulator_name] -http-proxy [proxy ip address]:[port]
official docs

Volley SSL error when uploading a file larger than 1mb (I/O error during system call, Connection reset by peer)

I tried adding a retry policy (https://stackoverflow.com/a/22169775/2098493)
but the error persist when file being uploaded is larger than 1mb.
W/System.err: com.android.volley.NoConnectionError: javax.net.ssl.SSLException: Write error: ssl=0xafc3fe00: I/O error during system call, Connection reset by peer
W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:151)
W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
W/System.err: Caused by: javax.net.ssl.SSLException: Write error: ssl=0xafc3fe00: I/O error during system call, Connection reset by peer
W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)
W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:765)
W/System.err: at com.android.okio.Okio$1.write(Okio.java:70)
W/System.err: at com.android.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:116)
W/System.err: at com.android.okio.RealBufferedSink.write(RealBufferedSink.java:44)
W/System.err: at com.android.okhttp.internal.http.RetryableSink.writeToSocket(RetryableSink.java:77)
W/System.err: at com.android.okhttp.internal.http.HttpConnection.writeRequestBody(HttpConnection.java:240)
W/System.err: at com.android.okhttp.internal.http.HttpTransport.writeRequestBody(HttpTransport.java:77)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:622)
W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:388)
W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:500)
W/System.err: at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
W/System.err: at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
W/System.err: at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:110)
W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
Thanks for your advice.
The solution was a combination of adding Volley Retry Policy and making sure back-end and server (nodejs/nginx) max uploaded file size are both set correctly.
//where RETRY_DEFAULT_TIMEOUT_MS = 5000, RETRY_DEFAULT_MAX_RETRIES = 3, RETRY_DEFAULT_BACKOFF_MULT = 2.0f
request.setRetryPolicy(new DefaultRetryPolicy(RETRY_DEFAULT_TIMEOUT_MS,
RETRY_DEFAULT_MAX_RETRIES,
RETRY_DEFAULT_BACKOFF_MULT));

SSLHandshakeException: Connection closed by peer

I have a simple code and there is an exception coming, can't figure out why?
My code:
Document document= Jsoup.connect("https://kolkatatrafficpolice.net/").get();
Stack trace:
javax.net.ssl.SSLHandshakeException: Connection closed by peer
W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
W/System.err: at com.android.okhttp.Connection.connectTls(Connection.java:235)
W/System.err: at com.android.okhttp.Connection.connectSocket(Connection.java:199)
W/System.err: at com.android.okhttp.Connection.connect(Connection.java:172)
W/System.err: at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
W/System.err: at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:247)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
W/System.err: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
W/System.err: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java)
W/System.err: at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:571)
W/System.err: at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:548)
W/System.err: at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:235)
W/System.err: at org.jsoup.helper.HttpConnection.get(HttpConnection.java:224)
W/System.err: at com.pritesh.trafficviolation.GetHtml.doInBackground(MainActivity.java:29)
That server is using an unrecognized certificate authority.
If this is your server, and you are intentionally doing this (e.g., this is a self-signed certificate), you would need to configure JSoup/OkHttp to use that self-signed certificate.
Otherwise, your problems lie with the server.

Categories

Resources