0

We all know that the browser is responsible for redirecting the request once it receives the response status code 3xx.

But this time, I am sending a request from the back end code of the application using URLConnection. My application is running on a tomcat server.

Now what if I get a response status code 3xx, will the tomcat itself take care of redirecting the request or should I handle it in my application as :

if(urlConnection.getResponseCode() == 302)
{
   // make a new request to URL found in Location Header
}
SME
  • 23
  • 7
  • 1
    Tomcat is not involved in downstream calls any more than a hotel you stay at is involved when you call someone on your cell phone. Your HTTP client will either follow the redirect or not, depending on its capabilities and how you have it configured. – chrylis -cautiouslyoptimistic- Nov 13 '20 at 06:04
  • Thank you @chrylis-cautiouslyoptimistic- – SME Nov 13 '20 at 06:09
  • 1
    For `java.io.Http[s]URLConnection` see methods `set[Instance]FollowRedirects` but warning: it doesn't handle a protocol change, such as redirecting http: to https: which is common. For new-since-11 `java.net.http.HttpClient` see `.Builder.followRedirects`. – dave_thompson_085 Nov 13 '20 at 09:57

0 Answers0