resttemplate调用
Map<String, Object> queryForHttp(String url, Map<String, Object> header, Map<String, Object> param, HttpMethod method) throws Exception{
// 默认使用Get方法查询
if (method == null)
method = HttpMethod.GET;
HttpHeaders headers = new HttpHeaders();
//设置默认为短连接
headers.add("Connection", "close");
if (!CollectionUtils.isEmpty(header)) {
for (String key : header.keySet()) {
headers.add(key, header.get(key).toString());
}
}
HttpEntity request = new HttpEntity<>(param, headers);
ResponseEntity<HashMap> exchange = restTemplate.exchange(url, method, request, HashMap.class);
HashMap result = null;
if (exchange != null && exchange.getBody() != null) {
result = exchange.getBody();
}
return result;
}
最轻松的学习方式莫过于在学习中找到属于自己的乐趣,与诸君共勉
浙公网安备 33010602011771号