title: HTTP FAILED: javax.net.ssl.SSLHandshakeException: Chain validation failed
body: <p>I tried to call an API with the OkHttp client, but it does not succeed in Android. The API is working fine on iOS and Postman.</p>
  <p>I'm getting a <code>SSLHandshakeException</code> in Android only. So, what would be the reason, and how to resolve it?</p>
  <p><strong>OkHttp libs</strong></p>
  <pre><code>implementation 'com.squareup.okhttp3:okhttp:3.9.0'
  implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
  </code></pre>
  <p><strong>Http Client</strong></p>
  <pre><code>HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
  logging.setLevel(HttpLoggingInterceptor.Level.BODY);
  OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
  if (BuildConfig.DEBUG)
      builder.addInterceptor(logging);
  OkHttpClient client= builder.build();
  </code></pre>
  <p><strong>Log:</strong></p>
  <pre><code>javax.net.ssl.SSLHandshakeException: Chain validation failed
      at com.android.org.conscrypt.SSLUtils.toSSLHandshakeException(SSLUtils.java:362)
      at com.android.org.conscrypt.ConscryptEngine.convertException(ConscryptEngine.java:1134)
      at com.android.org.conscrypt.ConscryptEngine.readPlaintextData(ConscryptEngine.java:1089)
      at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:876)
      at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:747)
      at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:712)
      at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.processDataFromSocket(ConscryptEngineSocket.java:849)
      at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.access$100(ConscryptEngineSocket.java:722)
      at com.android.org.conscrypt.ConscryptEngineSocket.doHandshake(ConscryptEngineSocket.java:238)
      at com.android.org.conscrypt.ConscryptEngineSocket.startHandshake(ConscryptEngineSocket.java:217)
      at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:299)
      at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:268)
      at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:160)
      at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)
      at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
      at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
      at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
  </code></pre>
  <p><strong>Tested Devices and OS Version</strong></p>
  <ol>
  <li>OnePlus 6T (Android 10)</li>
  <li>Samsung s5 (Android 9)</li>
  <li>Samsung A5 (android 6)</li>
  <li>Android Emulator (Android 11)</li>
  <li>LG Nexus (android 6)</li>
  </ol>