티스토리 뷰
http://hc.apache.org/httpclient-3.x/index.html
위 사이트에서 관련 라이브러리를 다운 받는다.
아래는 예제 코드 이다.
위 사이트에서 관련 라이브러리를 다운 받는다.
아래는 예제 코드 이다.
HttpClient client = null;
PostMethod post = null;
try
{
String url = "http://localhost/test.jsp";
client = new HttpClient(new MultiThreadedHttpConnectionManager());
post = new PostMethod(url);
// timeout 설정
HttpMethodParams hmp = new HttpMethodParams();
hmp.setSoTimeout(1000*3);
post.setParams(hmp);
// parameters
NameValuePair[] param = {
new NameValuePair("param1", "1"),
new NameValuePair("param2", "2"),
new NameValuePair("param3", "3")
};
post.setRequestBody(param);
int httpResultCode = client.executeMethod(post);
if(httpResultCode == HttpStatus.SC_OK)
{
InputStream in = null;
try
{
in = post.getResponseBodyAsStream();
content = inputStreamToString(in);
}
catch(Exception e)
{
// 오류 처리
}
finally
{
// inputstream close
if(in != null)
in.close();
}
}
else
{
// 요청 실패 처리
}
}
catch(Exception e)
{
// post 요청 오류 처리
}
finally
{
// post close
if(post != null)
post.releaseConnection();
}
'프로그래밍 > Java' 카테고리의 다른 글
| [mybatis] if 에서 문자열 비교시 NumberFormatException 해결 방법 (2) | 2011.08.04 |
|---|---|
| [SpringFramework] 한글 문제 (0) | 2011.07.29 |
| [ibatis] 동적 쿼리 실행 AutoResultMap 에러 (0) | 2010.05.28 |
| HTTP요청 인지 HTTPS 요청인지 확인하는 방법 (1) | 2010.05.19 |
| 다중 loop 한번에 빠져 나오기... (0) | 2010.05.14 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
