http请求中文乱码问题

HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
HttpEntity<String> requestEntity = new HttpEntity<String>((new JSONObject()).toString(), headers);
restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);

根据编码确定
StandardCharsets.UTF_8 的不同。



posted @ 2021-07-15 10:35  小匠人  阅读(440)  评论(0编辑  收藏  举报