0

Say for example I'm try to make a GET Request to www.testjson.com/json, However the response is retrieved from a different domain URL e.g. www.testjson.com/confirmJson.

Does Spring mvc support this, specifically restTemplate.exchange functionality.

I am currently doing this sort of thing, but I am getting an 500 status code (internal server error) and have no way of finding out what exactly is causing the error.

So can RestTemplate actually manage the redirect and provide the necessary JSON response or does it actually wait for the response from the url you provide hence the reason for getting the 500 internal server error?

Shavin Peiris
  • 81
  • 1
  • 9

1 Answers1

0

It is possible to let a RestTemplate automatically follow a redirect.

The server must respond with a Http 3xx and the location header set.

The RestTemplate 'understands' this response and issues a new GET request to the returned location.

This should work with default spring configuration.

See also follow-302-redirect-using-spring-resttemplate

Community
  • 1
  • 1