给大家分享一个spring自带的发送post请求的一个方法,postForObject()参数解释一下,第一个参数是请求地址,第二个是参数,第三个是返回类型。
private List<BeNotifyTradingResp> list() {
JSONArray ret=null;
Map<String, Object> args = new HashMap<String, Object>();
RestTemplate rt=new RestTemplate();
List<xxxx> l = null;
try {
String url = new StringBuffer("http:localhost:8080").toString();
logger.info("通知交易数据请求url:"+url);
ret=rt.postForObject(url, args, JSONArray.class);
// 转成list
}catch (Exception e) {
logger.error("获取通知交易数据失败",e);
}
return l;
}