403 Forbidden when I try to consume using Spring RestTemplate

1

I am trying to consume a web page service with RestTemplate of Spring . However I get the error 403, but if I consume the URL from PostMan then it does bring me the information without error. Does anyone know how I can solve this problem? I leave the code of the method I use to consume the URL:

 RestTemplate rt = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
    headers.set("Accept", MediaType.TEXT_HTML_VALUE);
    HttpEntity<?> entity = new HttpEntity<>(headers);

    HttpEntity<String> response = rt.exchange(URLRest, HttpMethod.GET, entity, String.class);
    return response.getBody(); 
    
asked by Diazal 21.05.2018 в 22:00
source

1 answer

1

Okay I know what was happening.

I was trying to consume a service using the HTTP protocol, however, the HTTP protocol was not allowed on the server, it only allowed HTTPS, so PostMan did not have any problem because it automatically changed the protocol without me noticing. I just had to change the protocol and that's it.

    
answered by 03.06.2018 в 08:00