I'm developing an Android App and I need to access an HTTPS address. I'm using Volley to request my data, but now i'm getting this error com.android.volley.NoConnectionError: java.io.IOException: Hostname '<address>' was not verified
To get the SSL factory i make this:
private static SSLSocketFactory getSocketFactory() {
SSLSocketFactory socketFactory = null;
try {
final CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
final BufferedInputStream bis = new BufferedInputStream(sContext.getResources().openRawResource(R.raw.cert)) ;
Certificate certificate;
try {
certificate = certificateFactory.generateCertificate(bis);
} finally {
bis.close();
}
final String keyStoreType = KeyStore.getDefaultType();
final KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", certificate);
final String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null);
socketFactory = sslContext.getSocketFactory();
} catch (Exception e) {
Log.w(TAG, Log.getStackTraceString(e));
}
return socketFactory;
}
The queue initialization:
final HttpStack stack = new HurlStack(null, getSocketFactory());
final Cache cache = new NoCache();
final Network network = new BasicNetwork(stack);
sRequestQueue = new RequestQueue(cache, network);
sRequestQueue.start();
Here's the stacktrace:
com.android.volley.NoConnectionError: java.io.IOException: Hostname 'url' was not verified
09-04 11:15:33.198 W/System.err﹕ at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:151)
09-04 11:15:33.198 W/System.err﹕ at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
09-04 11:15:33.198 W/System.err﹕ Caused by: java.io.IOException: Hostname 'hml.services.vivara.com.br' was not verified
09-04 11:15:33.198 W/System.err﹕ at com.android.okhttp.Connection.upgradeToTls(Connection.java:201)
09-04 11:15:33.198 W/System.err﹕ at com.android.okhttp.Connection.connect(Connection.java:151)
09-04 11:15:33.198 W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
09-04 11:15:33.198 W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
09-04 11:15:33.198 W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
09-04 11:15:33.198 W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
09-04 11:15:33.198 W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:208)
09-04 11:15:33.198 W/System.err﹕ at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
09-04 11:15:33.198 W/System.err﹕ at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
09-04 11:15:33.198 W/System.err﹕ at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:240)
09-04 11:15:33.198 W/System.err﹕ at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:210)
09-04 11:15:33.198 W/System.err﹕ at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:106)
09-04 11:15:33.198 W/System.err﹕ at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
I searched for the error, but I didn't find anything for my case. Can anyone help me?