aquitted-mind
aquitted-mind

Reputation: 303

curl POST to rest template

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].

Upvotes: 0

Views: 861

Answers (1)

Monzurul Shimul
Monzurul Shimul

Reputation: 8396

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.

Upvotes: 1

Related Questions