0
curl -v POST -d '[23,24]' https://serverurl/api/list/GetByIds --header "Accept:application/json" --header "Content-Type:application/json" --header "Authorization: Bearer XYZ" 

The above curl statement returns proper result. I am not sure how to send the same data using Spring RestTemplate.exchange . I don't need the whole code, I just want to know how I can send that list of integers [23,24].

2
  • You can use the exchange(RequestEntity<?> requestEntity, java.lang.Class<T> responseType) method. When you create parametrized RequestEntity you can add List<Integer> as the type of the Request entity. RequestEntity<List<Integer>> request = RequestEntity.post(new URI("http://example.com/bar")).accept(MediaType.APPLICATION_JSON).body(<actual list here>); Commented Mar 19, 2018 at 17:21
  • Thanks. I will try this out. Commented Mar 19, 2018 at 17:31

1 Answer 1

1

Try following:

List<Integer> integers = new ArrayList<>(); integers.add(23); integers.add(24); restTemplate.exchange("url", HttpMethod.POST, new HttpEntity<>(integers), new ParameterizedTypeReference<List<Integer>>() { }); 

Replace List<Integer> in new ParameterizedTypeReference<List<Integer>>() with your response model.

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.