RestTemplate发起http请求中文乱码问题解决方案
生活随笔
收集整理的這篇文章主要介紹了
RestTemplate发起http请求中文乱码问题解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON.toString()); String jsonStr = JSONObject.toJSONString(params); HttpEntity formEntity = new HttpEntity( jsonStr ,headers);
String result = restTemplate.getForObject(url, String.class);
閑話不多說,直接看代碼
總結
以上是生活随笔為你收集整理的RestTemplate发起http请求中文乱码问题解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NeDB——node嵌入式数据库
- 下一篇: Chapter03 第二节 const限