0

I'm using Rest template to make a request to a service. But I'm getting response code 400 and response null. I made the same call by postman, with the same parameters and I'm getting the body response. How do I get the body response?

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.add("Authorization", "Bearer " + token);
headers.add("kms_credencial", parametros.get("KMS_CREDENCIAL"));
headers.add("kms_credencial_tipo", parametros.get("KMS_CREDENCIAL_TIPO"));
        
  HttpEntity<MultiValueMap<String,Object>> entity = 
      new HttpEntity<MultiValueMap<String, Object>>(request,  headers);

  ResponseEntity<String> response = null;
    
  response = restTemplate.exchange(parametros.get("SERVICE_HUB2_BASE_URL") + "/fw/v1/pdf/kms/lote/assinaturas",
                    HttpMethod.POST, entity, String.class);

enter image description here

Could someone tell me what's wrong?

  • did you get an exception? try [catching `HttpStatusCodeException`](https://stackoverflow.com/a/51641899/1211547) – indybee Feb 12 '22 at 21:07

1 Answers1

0

I had the same problem. From what I've seen, ResteTemplate doesn't accept an error response (400, 500) with a 'large' body.

I still haven't found a solution, but I'm studying the parameters that the method accepts to see if any of them allows receiving a larger body