RestTemplate Chinese garbled code problem
Source code to see the cause of Chinese code solution
Causes the RestTemplate to receive parameters in the request response body with scrambled Chinese characters.
Source code to see the Reason for Chinese scrambled code
to take a closer look at the initialization parameter in the figure above, the default value of this parameter is as shown in the figure below.
you should know the cause of this problem and the solution. [after the RestTemplate is initialized, we will assign and modify it to the utf-8 code we need]
The solution
The SpringBoot project takes the following approach
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate(){
RestTemplate restTemplate = new RestTemplate(factory);
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
return restTemplate;
}
}
Read More:
- Solving the problem of Chinese garbled code in qtring
- After Oracle 11g is installed, SQL_ Plus.exe The problem of Chinese garbled in command window
- The problem of Chinese garbled data in MySQL
- Solve the problem of Chinese garbled code of actibpm plug-in in idea
- Solution to the problem of Chinese garbled in gradle console in idea
- Solve the problem of using logback console to print log Chinese characters in IDEA as garbled characters
- Chinese garbled fonts in win10 English system
- Solution of Chinese display garbled code in Git Bash
- Anaconda Matplotlib drawing Chinese garbled solution
- Solving Chinese garbled code in Java compressed file
- Solution of Chinese garbled code when using QT
- Chinese garbled code when vscode calls CMD to run C / C + +
- Python – [encoding] in Python os.system Solution to Chinese garbled code when calling CMD command
- Solution to garbled code problem after importing project in eclipse
- Solve the problem of Tomcat console and HTML garbled
- The garbled problem of hot deployment in nginx
- Solution of MySQL data garbled problem
- Solve the problem of garbled code when Python connects to ADB
- Configuring OpenGL in Chinese version of VS2010 and problem solving
- How to solve the problem of string to CString garbled code?