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].
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.