public void postHttp() throws UnsupportedEncodingException {
User user = new User();
user.setUid(1);
user.setName("张三");
String jsonParam = JSONObject.toJSONString(user);
log.info("jsonParam:{}", jsonParam);
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
List<NameValuePair> nameValuePairList = new ArrayList<>();
nameValuePairList.add(new BasicNameValuePair("authKey", "authKey"));
nameValuePairList.add(new BasicNameValuePair("initData", JSONObject.toJSONString(jsonParam)));
nameValuePairList.add(new BasicNameValuePair("title", "title"));
//创建httpPost,url代表你需要访问的远程地址
HttpPost httpPost = new HttpPost("url");
// 设置提交方式
httpPost.addHeader("Content-type", "application/x-www-form-urlencoded");
// 设置参数
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairList));

CloseableHttpResponse httpResponse = null;
try {
httpResponse = httpClient.execute(httpPost);
//取实体
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null) {
log.info("响应内容:{}", EntityUtils.toString(httpEntity, "utf-8"));
}
} catch (Exception e) {

} finally {
try {
if (httpClient != null) {
httpClient.close();
}
if (httpResponse != null) {
httpResponse.close();
}
} catch (Exception e) {

}
}

/**
* restTemplate
*/
//创建请求头
HttpHeaders headers = new HttpHeaders();
User user1 = new User();
user1.setUid(1);
user1.setName("张三");
String jsonParam1 = JSONObject.toJSONString(user1);

MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>();
postParameters.add("title", "title");
postParameters.add("authKey", "authKey");
postParameters.add("initData", JSONObject.toJSONString(jsonParam1));
org.springframework.http.HttpEntity<MultiValueMap<String, Object>> httpEntity
= new org.springframework.http.HttpEntity<>(postParameters, headers);

String string = restTemplate.postForObject("url", httpEntity, String.class);
log.info("响应内容:{}", string);
}

get

ResponseEntity<ProvinceAreaSiteVO> response = restTemplate.getForEntity
(sqUrl + "/motor-service/tms/province/area/center/site/get", ProvinceAreaSiteVO.class);
ProvinceAreaSiteVO provinceAreaSiteResultVOList =
BeanUtil.copyProperties(response.getBody(), ProvinceAreaSiteVO.class);


/**
* 省区
* @author keying
*/
@Data
public class ProvinceAreaSiteVO {

private Boolean status = false;

private String message;

private String statusCode;

private List<ProvinceAreaSiteResultVO> result;
}