首页 > 其他分享 >RestTemplate 请求 webservice 中文乱码问题解决【问题解决】

RestTemplate 请求 webservice 中文乱码问题解决【问题解决】

时间:2023-12-05 12:44:21浏览次数:32  
标签:return webservice request restTemplate 乱码 RestTemplate new

添加一个 Converter 设置 UTF-8 编码

@Configuration
public class RestTemplateConfig {

    @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();

        // 添加自定义的 ClientHttpRequestInterceptor 全局 JSON 請求
        restTemplate.setInterceptors(Collections.singletonList(new CustomClientHttpRequestInterceptor()));
        restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));

        restTemplate.getInterceptors().add((request, body, execution) -> {
            return execution.execute(request, body);
        });


        return restTemplate;
    }
}

标签:return,webservice,request,restTemplate,乱码,RestTemplate,new
From: https://www.cnblogs.com/liruilong/p/17876960.html

相关文章

  • 解决powershell conda init初始化乱码无法使用
    在powershell中使用condainit如果出现了下图最后一行的输出,且之后每次使用conda都提示你执行初始化,那就是跟题主一样的情况。原因有两个:1、你的“文档”库文件夹处在中文目录下2、windows默认编码不是UTF-8,但是conda初始化的时候是按UTF-8编码去生成powershell的配置文件这......
  • Python中execjs执行JS代码出现中文乱码
    1、乱码场景新建文件code.js,详情如下:functionfun(){return"我是fun函数";}在Python中执行此JS代码:1importexecjs23#读取js4withopen("code.js",encoding="utf8")asf:5jsCode=f.read()6print(jsCode)78#编辑......
  • kettle从入门到精通 第二十二课 kettle carte web服务中文乱码
    在windows上面carte服务的canvas画布展示的中文正常,但是在linux上面中文展示乱码,如下所示:原因:linux机器缺少字体所致。kettle源码中使用字体: 解决方法: 安装字体即可,无需重启机器,如果不生效,试着重启下carte服务,参考如下连接安装字体https://blog.csdn.net/weixin_42477......
  • webservice soap wsdl文件 学习
    WebServicesDescriptionLanguage,是为WSDLportTypes用于定义操作,包括多个operation(理解为函数),定义了操作的输入和输出数据流中可以出现的XML消息message理解operation所使用的参数集,内部每个part都是一个子参数,part中引用各种已定义的type的数据来定义各个子参数operation为......
  • 永久解决matplotlib中文乱码问题
    永久解决matplotlib中文乱码问题1.拷贝Simhei.ttf字体文件至以下目录/root/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf#根据自己系统酌情设置2.设置matplotlibrc文件(tensorflow)[root@bigdata~]#python>>>im......
  • 解决Jmeter响应报文中文乱码的问题-3种解决办法
    1.遇到问题:Jmeter在访问接口的时候,响应内容如果有中文可能会显示乱码。   2.问题分析:响应页面没有做编码处理,JMeter默认按照ISO-8859-1编码格式进行解析。   3.解决方案:办法一:通过后置处理器BeanShellPostProcessor 1)在线程组中添加后置处理器:Be......
  • jmeter 响应乱码
    Jmeter在做接口测试的时候的,如果接口响应的内容中有中文,jmeter的响应内容很可能显示乱码,为了规避这种出现乱码的问题,就要对jmeter的响应结果进行编码处理。打开jmeter进行接口、压力、性能等测试,出现以下乱码问题,如图解决方法一(临时修改):1、就是通过添加后置处理器,输入prev.setDa......
  • RestTemplate连续读取两个不同文件时报错Read timed out
    在项目上负责对接一些三方接口,鉴于之前的经验,选择使用RestTemplate来实现各种http请求,以及文件的读取。首先写了RestTemplate的配置类来配置基础信息,代码如下:@Configuration@ConditionalOnClass(value={RestTemplate.class,HttpClient.class})publicclassRestTemplateCo......
  • SAP PO 接口配置1:连通WebService-通过PO调用第三方接口
    背景说明SAP通过PO中间件进行接口调用,调用外部接口。外部接口可以用任意方式生成,常见的REST类型接口即可,关于如何使用python生成接口,其他章节另述。本教程的前置条件,PO中已配置BusinessSystems,并与SAP环境连通。1.测试接口这里以常见的post接口做示例,如有其他类型接口,需......
  • 解决WritePrivateProfileString写中文字符乱码问题
    使用WritePrivateProfileString写ini文件,在中文操作系统下写中文,没有问题,在俄文操作系统下,中文乱码。由于工程是Unicode,因此实际调用的是WritePrivateProfileStringW,而非WritePrivateProfileStringA。但是查看ini文件,发现是ANSI编码。查阅MSDN,发现有一句话:Ifthefilewascreat......