request = new LinkedMultiValueMap<>(); request.add("incType", "01"); request.add("phone", _resttemplate multi">
赞
踩
直接使用MultiValueMap
string url = Url + "/gsafety/alarmSynthesize/addIndustry";
MultiValueMap<String, Object> request = new LinkedMultiValueMap<>();
request.add("incType", "01");
request.add("phone", tel);
request.add("longitude", unitBaseInfo.getUnitPointX());
request.add("latitude", unitBaseInfo.getUnitPointY());
request.add("address", unitBaseInfo.getUnitAddress());
request.add("alarmDesc", desc);
JSONObject jo = restTemplate.postForObject(url, request, JSONObject.class);
log.info("调用警情推送接口返回结果result={}", jo);
ResponseEntity用于接受RestTemplate调用传回的数据,最后接口返回的是responseEntity.getBody的数据
HttpHeaders用于设置请求头参数 (可以设置的参数如下)
MultiValueMap用于设置请求体参数(上述代码直接传参就是这个map)
HttpEntity用于整合请求头+请求体,作为restTemplate的参数
/**
* @description:远程请求方法(同步)
* @author @author skj
* @date 2019年10月29日
*/
@Override
public JSONObject excute(MultiValueMap<String, Object> map,String url) throws Exception{
ResponseEntity<JSONObject> responseEntity = null;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String,Object>>(map, headers);
responseEntity = restTemplate.postForEntity(url, requestEntity,JSONObject.class);
JSONObject result = responseEntity.getBody();
return result;
}
eEntity.getBody();
return result;
}
![img](https://img-blog.csdnimg.cn/img_convert/5121b6800a867b306e811e918952fa92.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。