daily pastebin goal
16%
SHARE
TWEET

Android HTTP Post Request

Nesswit Apr 19th, 2013 404 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top