I check the certificate which is stored in app side and server side both are matching or not only trusted certificate should work
Below is my code and that code I am getting error in setDefaultSSLSocketFactory
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream caInput = new BufferedInputStream(context.getResources().openRawResource(R.raw.cert));
Certificate ca = cf.generateCertificate(caInput);
caInput.close();
// Create a KeyStore containing our trusted CAs
String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);
// Create a TrustManager that trusts the CAs in our KeyStore
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
// Create an SSLContext that uses our TrustManager
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null);
urlConnection = (HttpURLConnection) url.openConnection();
(HttpsURLConnection)urlConnection).setDefaultSSLSocketFactory(sslContext.getSocketFactory());
urlConnection.setRequestMethod(params[1]); //POST or GET
urlConnection.setRequestProperty("Content-type", "application/json");
urlConnection.setRequestProperty("Accept", "application/json");
urlConnection.setConnectTimeout(Constant.TIMEOUT_CONNECTION);
urlConnection.setRequestProperty("Authorization", basicAuth);//auth value
setDefaultSSLSocketFactory I am getting error cannot resolve method; where am I am going wrong? I have check the certificate both side certificate which is used in url and certificate which I am having but in setDefaultSSLSocketFactory is showing error so I cannot avail to test.
Update
I resolve the issue of cannot resolve method setDefaultSSl but now I am getting exception:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.