title: Adding a custom certificate to an OkHttp Client
body: <p>I am trying to make Android app, where I can get and parse HTML (from site which doesnt have API). I am using OkHttp. The site has untrusted (but valid) certificate. I am getting:</p>
  
  <pre><code>java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
  </code></pre>
  
  <p>I've already set up the official way (<a href="https://developer.android.com/training/articles/security-ssl#java" rel="noreferrer">https://developer.android.com/training/articles/security-ssl#java</a>) and now I need to link it with OkHttpClient.</p>
  
  <p>I tried</p>
  
  <pre><code>    OkHttpClient client = new OkHttpClient;
  
      OkHttpClient.Builder builder = client.newBuilder();
      builder.sslSocketFactory(sslcontext.getSocketFactory()).build();
  </code></pre>
  
  <p>But it doesnt work, and also it is deprecated.
  Thanks</p>