RestTemplate设置MediaType

String url = "http://testurl";
Map requestMap = new HashMap<>(); resultMap.put("param1", "value1"); resultMap.put("param2", "value2"); HttpHeaders headers = new HttpHeaders(); MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); headers.setContentType(type); headers.add("Accept", MediaType.APPLICATION_JSON.toString()); HttpEntity formEntity = new HttpEntity(JSONObject.toJSONString(requestMap), headers);
RestTemplate restTemplate
= new RestTemplate(); String result = restTemplate.postForObject(url, formEntity, String.class);

 

转载于:https://www.cnblogs.com/wanbao/p/9774182.html

你可能感兴趣的:(RestTemplate设置MediaType)