android:Trust anchor for certification path not found.

今天搞webservice,后台是https的,然后遇到了java.security.cert.CertPathValidatorException:Trust anchor for certification path not found.

看说明应该是少了签名.解决方案,在请求前添加:

 try {

                TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {

                    public X509Certificate[] getAcceptedIssuers() {

                        return new X509Certificate[0];

                    }

                    @Override

                    public void checkClientTrusted(X509Certificate[] certs, String authType) {

                    }

                    @Override

                    public void checkServerTrusted(X509Certificate[] certs, String authType) {

                    }

                }};

                SSLContext sc = SSLContext.getInstance("SSL");

                sc.init(null, trustAllCerts, new SecureRandom());

                HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

                HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {

                    @Override

                    public boolean verify(String arg0, SSLSession arg1) {

                        return true;

                    }

                });

            } catch (Exception ignored) {

                ignored.printStackTrace();

            }

你可能感兴趣的:(android:Trust anchor for certification path not found.)