2

I am using Okhttp3 in my android application to download files. I am having problem with https urls.

I have two URLS

    String url1 = "https://cbsenet.nic.in/cbsenet/PDFDEC2014/Paper%20III/D-01-3.pdf";
    String url2 = "https://www.ugcnetonline.in/question_papers/June2014_paper-II/J-02-14-II.pdf";

url2 is working fine while for url1 I am getting exception

Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I have created a sample java program to demonstrate the problem

public static void main(String[] args) throws IOException {

    String url1 = "https://cbsenet.nic.in/cbsenet/PDFDEC2014/Paper%20III/D-01-3.pdf";
    String url2 = "https://www.ugcnetonline.in/question_papers/June2014_paper-II/J-02-14-II.pdf";

    Request request = new Request.Builder()
            .url(url1)
            .build();

    OkHttpClient client = new OkHttpClient();
    Response response = client.newCall(request).execute();
    System.out.println(response.body().string());
}
mdolata
  • 184
  • 12
hard coder
  • 5,449
  • 6
  • 36
  • 61

0 Answers0