I have a little problem with SSL Validation in my application. As I find over internet in FourSquare's documentation they suggest validation like this : SSL Calidation, but the problem is that I'm using an HttpsURLConnection
and I want to use that class instead of DefaultHttpClient
. So when I replace client in getTolerantClient
with HttpsURLConnection
and try to do this it's showing me some errors :
public HttpsURLConnection getTolerantClient() {
HttpsURLConnection client = new HttpsURLConnection();
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) client.getConnectionManager().getSchemeRegistry().getScheme("https").getSocketFactory();
final X509HostnameVerifier delegate = sslSocketFactory.getHostnameVerifier();
if(!(delegate instanceof MyVerifier)) {
sslSocketFactory.setHostnameVerifier(new MyVerifier(delegate));
}
return client;
}
like :
The method getConnectionManager() is undefined for the type HttpsURLConnection
&
The method getHostnameVerifier() is undefined for the type SSLSocketFactory
So any idea how can I use this in my situation? Thanks in advance!