public class HttpClient {
public String client(String url, HttpMethod method, MultiValueMap<String, String> params) {
RestTemplate client = new RestTemplate();
client.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// headers.set("x-dyeing", "xxx");
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(params, headers);
ResponseEntity<String> response = client.exchange(url, HttpMethod.POST, requestEntity, String.class);
return response.getBody();
}
public static void main(String[] args) {
MultiValueMap<String, String> params= new LinkedMultiValueMap<String, String>();
params.add("appId", "abc123");
HttpClient httpClient = new HttpClient();
HttpMethod method = HttpMethod.POST;
String result = httpClient.client("http://xxx/api/v1/xxx/xxx", method, params);
Map<String, Object> resultMap = JsonUtil.jsonToBean(result, HashMap.class);
System.out.println(resultMap);
}
}