Nesswit

Android HTTP Post Request

Apr 19th, 2013
444
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * HTTP POST 전송
  3.  * @param url 목적 URL
  4.  * @param params 함께 보낼 파라미터
  5.  *
  6.  * @return Response String
  7.  */
  8. private String httpRequestPost(final String url, final ArrayList<BasicNameValuePair> params) {
  9.     //타임아웃 설정
  10.     final int timeoutSeconds = 15;
  11.    
  12.     //Callable 선언
  13.     final Callable<String> postCallable = new Callable<String>() {
  14.         @Override
  15.         public String call() throws Exception {
  16.             final HttpClient client = new DefaultHttpClient();
  17.             final UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params, HTTP.UTF_8);
  18.             final HttpResponse responsePost = client.execute(new HttpPost(url).post.setEntity(ent));
  19.             final HttpEntity resEntity = responsePost.getEntity();
  20.             return EntityUtils.toString(resEntity);
  21.         }
  22.     };
  23.  
  24.     try {
  25.         //callable 시작
  26.         final Future<String> postFuture = es.submit(postCallable);
  27.  
  28.         //결과값 반환
  29.         return postFuture.get(timeoutSeconds, TimeUnit.SECONDS);
  30.     } catch (Exception e) {}
  31.     return null;
  32. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×