zoukankan      html  css  js  c++  java
  • springboot restTemplate 访问微信接口出现乱码问题

    设置编码为utf-8 最好设置一下     我的刚开始没设置是正常的,换了台电脑就乱码了 

    
    
    Charset charset = StandardCharsets.UTF_8;

    @Bean
    public RestTemplate restTemplate(){ RestTemplate restTemplate = new RestTemplate(); //这里处理编码问题 请求微信接口时不指定编码 返回的昵称 地区 等信息可能会乱码 List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters(); for (HttpMessageConverter<?> messageConverter : messageConverters) { if (messageConverter instanceof StringHttpMessageConverter) { ((StringHttpMessageConverter) messageConverter).setDefaultCharset(charset); } if (messageConverter instanceof MappingJackson2HttpMessageConverter) { ((MappingJackson2HttpMessageConverter) messageConverter).setDefaultCharset(charset); } if (messageConverter instanceof AllEncompassingFormHttpMessageConverter) { ((AllEncompassingFormHttpMessageConverter) messageConverter).setCharset(charset); } } return restTemplate; }
  • 相关阅读:
    Eighth scrum meeting
    Seventh scrum meeting
    Sixth scrum meeting
    Fifth scrum meeting
    Forth scrum meeting
    Third scrum meeting
    2019-07-25 L430 生物 GPS
    L429 Why Do Smart People Do Foolish Things?
    L427 长难句
    L426
  • 原文地址:https://www.cnblogs.com/rchao/p/12560282.html
Copyright © 2011-2022 走看看