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.

1
  • You’re also mixing up a GET request with a POST template? Commented May 13, 2020 at 7:59

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.