1

String url = "http://localhost:8080/get/{var1}?var2={var2}";

I am using restTemplate.postForEntity(url, entity, String.class, var1, var2); //where var1, var2 are uriVariables

Now I am getting some error while I am trying to hit via restTemplate and I believe it might be due to incorrect positioning of the uriVariables. So is there a way to get the URL information that is generated by the restTemplate object. So that I can check whether the restTemplate is hitting correct endpoint or not.

KNDheeraj
  • 834
  • 8
  • 23

1 Answers1

1
     String url = UriComponentsBuilder
                .fromHttpUrl(http://localhost:8080/get)
                .queryParam("var1", <value of var1>)
                .queryParam("var2", <value of var2>);
                .toUriString()

and then use this url with resttemplate

  ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, null, String.class);

HttpStatus statusCode = responseEntity.getStatusCode();
System.out.println("status code - " + statusCode);
String userDetails = responseEntity.getBody();
System.out.println("response body - " + userDetails);
HttpHeaders responseHeaders = responseEntity.getHeaders();
System.out.println("response Headers - " + responseHeaders);
Arvind Kumar
  • 459
  • 5
  • 21