import org.apache.http.HttpHost;
import org.apache.http.conn.params.ConnRoutePNames;
..................................
public String requestPOST(String reqUrl, String reqParam, HashMap<String, Object> extendedHeader, String contentType, String charset) {
String serverResponse = new String();
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpHost proxy = new HttpHost("127.0.0.1", 8888);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
HttpPost postRequest = new HttpPost(reqUrl);
/** 추가 Header 필요한 경우 설정 **/
if(extendedHeader != null){
Set<String> keySet = (Set<String>)extendedHeader.keySet();
Iterator<String> headerKeys = keySet.iterator();
while(headerKeys.hasNext()){
String headerKey = headerKeys.next();
postRequest.addHeader(headerKey, (String)extendedHeader.get(headerKey));
}
}
/** requParam은 json 형태의 String value **/
StringEntity input = new StringEntity(reqParam, charset);
input.setContentEncoding(charset);
input.setContentType(contentType);
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
serverResponse = catchResponse(response, charset);
logger.debug("shutdown!!!!!!!!!!!!!!!!!!!!!!!!!!");
httpClient.getConnectionManager().shutdown();
// Thread.sleep(5000);
} catch (MalformedURLException e) {
logger.error("########## ERROR IN REQUEST POST - MalformedURLException : "+ this.getClass());
logger.error(e);
e.printStackTrace();
serverResponse = null;
}catch(IOException e) {;
logger.error("########## ERROR IN REQUEST POST - IOException: "+ this.getClass());
logger.error(e);
e.printStackTrace();
serverResponse = null;
}catch(Exception e) {;
logger.error("########## ERROR IN REQUEST POST - Exception : "+ this.getClass());
logger.error(e);
e.printStackTrace();
serverResponse = null;
}
return serverResponse;
}
'Dev > Orvercome 3sec memory' 카테고리의 다른 글
Eclipse "Remote Debugging" Setting with JBoss Portal, Fuse (0) | 2015.03.10 |
---|---|
Native와 Mobile Web통신 시 반환 메서드명 랜덤 생성 (0) | 2013.07.24 |
생각하지 못 했던, 자바스크립트 호출이 안 된 이유 (0) | 2013.04.15 |
MySQL의 BETWEEN 조건절 결과 데이터 범위 (0) | 2013.03.07 |
Server to Server Http POST 요청 시 파라미터 처리방법 2가지와 Entity 클래스 (4) | 2013.03.06 |