How to check my API URL SSL and NON-SSL support in Android app?

I have an android app and some response from URLs, that URL contains SSL supporting also NON-SSL support URLS. now i write the code for SSL support and working nicely. i want to check both a conditions if SSL and NON-SSL site also supoorted.

what i tryied here,

String url = AdRequestParam.getURL();
HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;  
DefaultHttpClient client = new DefaultHttpClient();

//SSL
SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
registry.register(new Scheme("https", socketFactory, 443));
SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());

// Set verifier     
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);

1 answer

  • answered 2018-01-12 04:41 Coder_07

    I can fix this issues y using url.startsWith("http://"), to write the condition and make then execute as per the requesting URLs.