I am trying to execute a HTTP GET request that I can execute properly in Postman in my Spring Boot application using the RestTemplate class.
This is the code I am using to send the request:
RestTemplate restTemplate = new RestTemplate();
String response = restTemplate.getForObject(url, String.class);
When I execute this the response variable contains only weird characters. My initial thought was that I was using the wrong encoding. The response I see in Postman indicates that the correct encoding is UTF-8, so I added this code:
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));
I also though I was using the wrong "Accept" header, so I also added this code:
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add(new HeaderRequestInterceptor("Accept", MediaType.ALL_VALUE));
restTemplate.setInterceptors(interceptors);
Both these adjustments do not fix the issue. Is there any other way to fix this?
I am happy to provide more info if needed! Thanks in advance.