Answer the question
In order to leave comments, you need to log in
How to solve server connection problem on Android API 20 and below?
The application accesses the php file on the server using OkHttp. On Android API 20 and above, everything works. If the API is below 20, then the following errors occur:
07-17 16:19:58.612 1509-1524/com.example.verum.optron001 W/System.err: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
07-17 16:19:58.612 1509-1524/com.example.verum.optron001 W/System.err: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:381)
07-17 16:19:58.616 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:302)
07-17 16:19:58.616 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:270)
07-17 16:19:58.620 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:162)
07-17 16:19:58.624 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
07-17 16:19:58.624 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
07-17 16:19:58.624 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
07-17 16:19:58.624 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
07-17 16:19:58.624 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
07-17 16:19:58.624 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
07-17 16:19:58.624 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
07-17 16:19:58.624 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
07-17 16:19:58.624 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
07-17 16:19:58.624 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
07-17 16:19:58.628 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
07-17 16:19:58.628 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
07-17 16:19:58.628 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
07-17 16:19:58.628 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
07-17 16:19:58.628 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
07-17 16:19:58.632 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
07-17 16:19:58.632 1509-1524/com.example.verum.optron001 W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
07-17 16:19:58.632 1509-1524/com.example.verum.optron001 W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
07-17 16:19:58.632 1509-1524/com.example.verum.optron001 W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
07-17 16:19:58.632 1509-1524/com.example.verum.optron001 W/System.err: at java.lang.Thread.run(Thread.java:856)
07-17 16:19:58.632 1509-1524/com.example.verum.optron001 W/System.err: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
07-17 16:19:58.632 1509-1524/com.example.verum.optron001 W/System.err: at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:276)
07-17 16:19:58.636 1509-1524/com.example.verum.optron001 W/System.err: at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:197)
07-17 16:19:58.636 1509-1524/com.example.verum.optron001 W/System.err: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:584)
07-17 16:19:58.636 1509-1524/com.example.verum.optron001 W/System.err: at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
07-17 16:19:58.636 1509-1524/com.example.verum.optron001 W/System.err: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:378)
07-17 16:19:58.636 1509-1524/com.example.verum.optron001 W/System.err: ... 23 more
07-17 16:19:58.636 1509-1524/com.example.verum.optron001 W/System.err: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
07-17 16:19:58.636 1509-1524/com.example.verum.optron001 W/System.err: ... 28 more
public void signInClick(View view) {
numberField = findViewById(R.id.numberPhone);
passwordField = findViewById(R.id.password);
numberPhone = numberField.getText().toString();
String password = passwordField.getText().toString();
/*String hostname = "000webhostapp.com";
CertificatePinner certificatePinner = new CertificatePinner.Builder()
.add(hostname, "sha256/c95d249a927d79db828e18296aee11d211fb7d95327971277ff83b13f8d5b466=")
.build();*/
OkHttpClient client = new OkHttpClient();;
String url = "https://optron001.000webhostapp.com/signIn.php?numberPhone=" + numberPhone + "&password=" + password;
//создаем запрос к серверу
Request request = new Request.Builder().url(url).build();
//выполняем запрос и получаем ответ
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
LoginActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() { showMessege("Отсутствует подключение к интеренету"); } });
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
final byte[] check = response.body().bytes();
LoginActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if(check[0] == 49)
startMaps();
else if(check[0] == 50)
showMessege("Несуществующий пользователь");
else
showMessege("Неверный пароль");
}
});
}
else
LoginActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() { showMessege("Сервер недоступен"); } });
}
});
}
Answer the question
In order to leave comments, you need to log in
The log says that the problem is with the ssl certificate. Or you need to edit the certificate on the server, or disable ssl verification on the device.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question