0

In Postman I'm sending the following request: img1 img2

I'm getting the expected response, with the limit being taken into account.

Here's my Spring RestTemplate implementation:

        String url = "https://somedomain.com/api/v1/xyz";

        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        map.add("limit", "1");

        HttpHeaders headers = new HttpHeaders();
        headers.set("Authorization", "<CENSORED>");
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);

        ResponseEntity<SomeClass> response;
        try {
            response = restTemplate.exchange(url, HttpMethod.GET, request, SomeClass.class);
        } catch (RestClientException e) {
            // not important
        }

In the response, the limit is not taken into account. It's like not having sent the limit at all.

Here's what my application logs:

==============================request start==============================
URI         : https://somedomain.com/api/v1/xyz
Method      : GET
Headers     : [Accept:"application/json, application/*+json", Authorization:"<CENSORED>", Content-Type:"application/x-www-form-urlencoded;charset=UTF-8", Content-Length:"7"]
Request body: limit=1
===============================request end===============================
==============================response start=============================
Status code  : 200 OK
Status text  : OK
Headers      : // some headers
Response body: // response
==============================response end===============================

Any idea what might be the problem? If I set Content-Length to 7 manually in Postman it still works.

Thank you!

Chrissy
  • 1
  • 2
  • From your logs, it looks like , it is receiving limit=1. You probably need to check your api part about why it is not implementing limit=1. – YoManTaMero Jul 13 '20 at 22:44
  • It's not my API, I'm trying to consume a remote API. The logs are from my end, not the API server. – Chrissy Jul 13 '20 at 22:46
  • Why are you sending form data into a GET request? Get requests are cachable. – YoManTaMero Jul 13 '20 at 22:52
  • Because that's how the API is structured, I'm just trying to use it. – Chrissy Jul 13 '20 at 22:54
  • Similar problem (this will probably help you) https://stackoverflow.com/questions/56544432/how-to-send-body-as-a-json-in-resttemplate-to-get-data-from-api – YoManTaMero Jul 13 '20 at 23:34

0 Answers0