D
D
druper2019-04-11 23:29:01
Spring
druper, 2019-04-11 23:29:01

Why is RestTemplate sending request with wrong uri?

@RequestMapping("/home")
    public String home() {
        RestTemplate restTemplate = new RestTemplate();
        String address = "Автодорожная, 15";
        UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(LOCAL_GEOCODING_URI)
                .queryParam("address", address);

        logger.warn("Calling api with: " + builder.toUriString());
        ResponseEntity<String> response = restTemplate.getForEntity(builder.toUriString(), String.class);
        return response.toString();
    }

I see in the log that the address parameter is not the same:
com.example.controller.GeoCodingController: Calling api with: http://localhost:8080?address=%D0%90%D0%B2%D1%82%D0%BE%D0%B4%D0%BE%D1%80%D0%BE%D0%B6%D0%BD%D0%B0%D1%8F,%2015
org.springframework.core.log.CompositeLog: HTTP GET http://localhost:8080?address=%25D0%2590%25D0%25B2%25D1%2582%25D0%25BE%25D0%25B4%25D0%25BE%25D1%2580%25D0%25BE%25D0%25B6%25D0%25BD%25D0%25B0%25D1%258F,%252015

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question