Created
August 30, 2012 05:48
-
-
Save benelog/3522924 to your computer and use it in GitHub Desktop.
Http client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DefaultHttpClient client = new DefaultHttpClient(); | |
// HttpClient를 매번생성하지 않고 ThreadSafeClientConnManager 를 활용하는 것이 바람직 | |
HttpPost request = new HttpPost(apiUrl); | |
UrlEncodedFormEntity formEntity = createEntity(userId, password); | |
request.setEntity(formEntity); | |
InputStream contentStream = null; | |
String resContent = null; | |
try { | |
HttpResponse response = client.execute(request); | |
HttpEntity resEntity = response.getEntity(); | |
contentStream = resEntity.getContent(); | |
resContent = IoUtils.readFully(contentStream); | |
} catch (IOException e) { | |
throw new IllegalStateException("fail to connect api server :" + apiUrl ,e); | |
} finally { | |
IoUtils.close(contentStream); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment