Lolipop 5.0 handshaking with https problem solved?

Step wise follow :

  1. Add this class =>

public class MySSLSocketFactory extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance("TLS");

public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {

TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {

public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {

public X509Certificate[] getAcceptedIssuers() {
return null;

sslContext.init(null, new TrustManager[]{tm}, null);

public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {

socket = sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
((SSLSocket) socket).setEnabledCipherSuites(new String[]{"RC4-MD5", "DES-CBC-SHA", "DES-CBC3-SHA"});

return socket;

public Socket createSocket() throws IOException {
return sslContext.getSocketFactory().createSocket();


step 2: whatever method you used rectrofit ya http before that use this protocolo for handshaking.

Use this Http protocol for Request

public static HttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);

MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);

HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));

ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();


Rquesting Post method for post request.

public String POST(String url, String data, Map header, Context context) {

InputStream inputStream = null;
String result = "";

Log.d("result", "" + url);

try {
HttpClient httpclient = getNewHttpClient();
HttpPost httpPost = new HttpPost(url);
String json = "";
StringEntity se = new StringEntity(data);
for (String key : header.keySet()) {
httpPost.setHeader(key, header.get(key));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-Type", "application/json");
HttpResponse httpResponse = httpclient.execute(httpPost);
inputStream = httpResponse.getEntity().getContent();
if (inputStream != null)
result = convertInputStreamToString(inputStream);
result = "Did not work!";
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());

return result;


Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google



Best Watch Store

Popular Posts

Contact Form


Email *

Message *