Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * HTTP POST 전송
- * @param url 목적 URL
- * @param params 함께 보낼 파라미터
- *
- * @return Response String
- */
- private String httpRequestPost(final String url, final ArrayList<BasicNameValuePair> params) {
- //타임아웃 설정
- final int timeoutSeconds = 15;
- //Callable 선언
- final Callable<String> postCallable = new Callable<String>() {
- @Override
- public String call() throws Exception {
- final HttpClient client = new DefaultHttpClient();
- final UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params, HTTP.UTF_8);
- final HttpResponse responsePost = client.execute(new HttpPost(url).post.setEntity(ent));
- final HttpEntity resEntity = responsePost.getEntity();
- return EntityUtils.toString(resEntity);
- }
- };
- try {
- //callable 시작
- final Future<String> postFuture = es.submit(postCallable);
- //결과값 반환
- return postFuture.get(timeoutSeconds, TimeUnit.SECONDS);
- } catch (Exception e) {}
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement