码迷,mamicode.com
首页 > Web开发 > 详细

RestTemplate发起http请求中文乱码问题解决方案

时间:2019-06-05 17:47:39      阅读:923      评论:0      收藏:0      [点我收藏+]

标签:pen   pre   中文乱码问题   ToJson   ons   temp   dia   headers   form   

        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请求中文乱码问题解决方案

标签:pen   pre   中文乱码问题   ToJson   ons   temp   dia   headers   form   

原文地址:https://www.cnblogs.com/zjting/p/10980966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!