In Android Defaulthttpclient, the timeout setting requires calling the Httpconnectionparams.setconnectiontimeout method, such as (31~35 line code for the following code):
Ref: Timeout in defaulthttpclient Class Android
/** the method of sending the POST request * @param the key-value pair of the params request parameter. * @param URL * @param encoding * @param setTimeout identifies whether the connection timeout is set. * @param connectiontimeout If the connection time-out is set, the connection times out. * @return * @throws malformedurlexception * @throws ioexception * @throws jsonexception * @throws parseexception */private Boolean postsend (Final map<string, string> params,final string url, Final String encoding, Boolean setTimeout, Fina l int connectiontimeout) throws Malformedurlexception, IOException, jsonexception,parseexception {//Encapsulates a key-value pair for the request parameter. list<basicnamevaluepair> pairs = new arraylist<basicnamevaluepair> (); for (entry<string, String> Param:params.entrySet ()) {Pairs.add (New Basicnamevaluepair (Param.getkey (), Param.getvalue ()));} The entity that encapsulates the request parameter. urlencodedformentity entity = new urlencodedformentity (pairs,encoding);//use a POST request. HttpPost post = new HttpPost (URL);p ost.setentity (entity);//Use Defaulthttpclient to specify the request to get the response information. Defaulthttpclient client = new Defaulthttpclient ();//Set Connection timeout. if (setTimeout) {final Httpparams httpParameters = Client.getparams (); Httpconnectionparams.setconnectiontimeout (Httpparameters, connectiontimeout);} HttpResponse response = Client.execute (POST); BufferedReader reader = new BufferedReader (New InputStreamReader (Response.getentity (). GetContent (), encoding));// Use thread-safe stringbuffer.stringbuffer buffer = new StringBuffer (); String ln = null;while ((ln = reader.readline ()) = null) buffer.append (LN). Append (System.getproperty ("Line.separator") );//Line wrapping according to operating system platform.//Pass JSON to service processing. Final String rawjsonstr = buffer.tostring ();//test only://log.i ("Sysout", RAWJSONSTR); resultaqidays = Convertjsontoaqidaylist (RAWJSONSTR); return Response.getstatusline (). GetStatusCode () = = 200; Equals 200 indicates a successful send.}
Android-defaulthttpclient set timeout.