Android HttpClient Settings timeout
3.X is like this.
HttpClient httpclient=new defaulthttpclient ();
4.3 Is this.
Closeablehttpclient httpclient = Httpclients.createdefault ();
Of course, the above changes are just a few small changes, everyone look at the API everyone will be.
I want to talk about is the time-out setting, HttpClient has three kinds of timeout settings, recently busy, no time to specific summary, later on, I will talk about some of the simplest and most easy-to-use method of time-out.
This is a 3. Timeout setting method for X
HttpClient client = new HttpClient ();
Client.setconnectiontimeout (30000);
Client.settimeout (30000);
HttpClient httpclient= new HttpClient ();
Httpclient.gethttpconnectionmanager (). Getparams (). Setconnectiontimeout (5000);
Timeout setting for 4.X version (obsolete after 4.3)
HttpClient httpclient=new defaulthttpclient ();
Httpclient.getparams (). Setparameter (coreconnectionpnames.connection_timeout,2000);//Connection time
Httpclient.getparams (). Setparameter (coreconnectionpnames.so_timeout,2000);//Data transfer time
4.3 Version timeout setting
Closeablehttpclient httpclient = Httpclients.createdefault ();
HttpGet httpget=new httpget ("http://www.baidu.com");//http Get request (post similarity)
Requestconfig requestconfig = Requestconfig.custom (). SetSocketTimeout. Setconnecttimeout (). build ();//Set Request and Transfer timeout
Httpget.setconfig (Requestconfig);
Httpclient.execute (HttpGet),//Execute request
btw,4.3 version does not set timeout, once the server is not responding, wait time n long (>24 hours)