Retrofit handle the SSLHandshakeException

Updated 18 January 2024

Save

This blog focuses on Retrofit handling the SSLHandshakeException.

Using Retrofit as your network library is a very good option for Android app development. But many a time we face the SSLHandshakeException (java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.) to be particular.

This error means that the secure URL you are requesting is not allowing your Retrofit to connect and fetch data.
If you can manage to change the usage from https to http then this will work perfectly fine and you don’t need to change anything.

But, if you can’t then you need to modify your retrofit Request builder object ( OkHttpClient.Builder to be particular) so that your application can fetch the data and the exception mentioned in the title is not a hurdle anymore.

Logical Approach

You need to modify your  OkHttpClient.Builder object in your Retrofit request so that your request can create a certificate that can be trusted by your server and your server can allow access to your request.

CODE

Modified OkHttpClient.Builder Object.

using this object in your retrofit request.

That’s All.

Keep coding and Keep Sharing.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


22 comments

  • อุรคินทร์ เต็มรัตน์
    • anchit (Moderator)
  • Qudratilla
    • anchit (Moderator)
  • Mohana
  • MOHAMED ABO SAGED
  • Bill Crandell
    • anchit (Moderator)
  • Bill Crandell
    • anchit (Moderator)
  • Nicodemus Ojwee
    • anchit (Moderator)
  • Deepak
    • anchit (Moderator)
  • Feryal
    • anchit (Moderator)
  • Cristhian Ruiz
    • anchit (Moderator)
  • Ivan
    • anchit (Moderator)
  • Fabiola Rodriguez
    • Akshay Singh (Moderator)
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home