DefaultHttpClient hangs on execute() method in lollipop

179 views Asked by At

In one of our old project we are using DefaultHttpClient for networking. its working fine below lollipop devices but in lollipop get request hangs execute method call. We are creating HttpClient like this.

public static MyHttpClient createHttpClient(Context ctx) {    
        try {
            if(mgr == null){            
                SSLSocketFactory sf = SSLSocketFactory.getSocketFactory();        
                sf.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);        

                httpParameters = new BasicHttpParams();        
                HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1);        
                HttpProtocolParams.setContentCharset(httpParameters, HTTP.UTF_8);
                HttpConnectionParams.setConnectionTimeout(httpParameters, HOST_REACH_TIMEOUT); 
                HttpConnectionParams.setSoTimeout(httpParameters, HOST_REACH_TIMEOUT);

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

                mgr = new ThreadSafeClientConnManager(httpParameters, registry);
            }
            return new MyHttpClient(mgr, httpParameters);    
        } catch (Exception e) {        
            return new MyHttpClient(ctx);    
        }
    }

We are also setting timeouts. Any idea why its freezing there and how we can fix that?

Edit: one more thing that i have missed. It only happens when we hit same URL 3rd time. First two times it works fine.

1

There are 1 answers

0
greenapps On BEST ANSWER

Instantiate every time a new mgr.