Skip to content

Spring Rest Template always return 500

i use Rest Template to consume a rest web service, However i always get 500 although when I test with postman i get 200

Here is Rest template code :

 private String callWs(int page) {
        final HttpHeaders headers = new HttpHeaders();
        headers.add(HttpHeaders.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36");
        headers.add(HttpHeaders.ACCEPT, "*/*");
        headers.add(HttpHeaders.ACCEPT_ENCODING, "gzip, deflate, br");
        headers.add(HttpHeaders.CONNECTION, "keep-alive");
        headers.add(HttpHeaders.COOKIE, "country-code=MA");
        headers.add(HttpHeaders.CACHE_CONTROL, "no-cache");
        final HttpEntity<?> entity = new HttpEntity<>(headers);
        final String urlTemplate = UriComponentsBuilder.fromHttpUrl(BASE_URL2)
                .queryParam("action", "ajax")
                .queryParam("rs", "JsonCategories")
                .queryParam("rsargs[]", "1")
                .queryParam("rsargs[]", "معلومات_ونصائح_طبية")
        final ResponseEntity<String> exchange =

        return exchange.getBody();

Postman response :

enter image description here

RestTemplate Error :

There was an unexpected error (type=Internal Server Error, status=500).
500 Internal Server Error: [Exception encountered, of type &quot;ArgumentCountError&quot; ]
org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Internal Server Error: [Exception encountered, of type &quot;ArgumentCountError&quot;


Try passing the array in one parameter rsargs[] and not in two as you do.

.queryParam("rsargs[]", new String[]{"1", "معلومات_ونصائح_طبية"})