Android开发基础教程:定义HttpPost连接超时

Android开发基础教程:定义HttpPost连接超时

public static String test(String URL, List<BasicNameValuePair> params) {           HttpPost httpPost = new HttpPost(URL);           String returnString = "";           HttpParams httpParameters = new BasicHttpParams();              try {               UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(                       params, "utf-8");               httpPost.setEntity(urlEncodedFormEntity);               HttpConnectionParams.setConnectionTimeout(httpParameters, 3000);               HttpClient httpClient = new DefaultHttpClient(httpParameters);               HttpResponse httpResponse = httpClient.execute(httpPost);               HttpEntity httpEntity = httpResponse.getEntity();               InputStream inputStream = httpEntity.getContent();               BufferedInputStream bufferedInputStream = new BufferedInputStream(                       inputStream);               ByteArrayBuffer byteArrayBuffer = new ByteArrayBuffer(50);               int current = 0;               while ((current = bufferedInputStream.read()) != -1) {                   byteArrayBuffer.append(current);               }               returnString = EncodingUtils.getString(byteArrayBuffer                       .toByteArray(), "utf-8");           } catch (UnsupportedEncodingException e) {               e.printStackTrace();           } catch (ClientProtocolException e) {               e.printStackTrace();           } catch (IOException e) {               e.printStackTrace();           }           return returnString;       }  

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/pxjdg.html