title: Android HttpURLConnection: Handle HTTP redirects
body: <p>I'm using <code>HttpURLConnection</code> to retrieve an URL just like that:</p>
  
  <pre><code>URL url = new URL(address);
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setInstanceFollowRedirects(true);
  // ...
  </code></pre>
  
  <p>I now want to find out if there was a redirect and if it was a permanent (301) or temporary (302) one in order to update the URL in the database in the first case but not in the second one.</p>
  
  <p>Is this possible while still using the redirect handling of <code>HttpURLConnection</code> and if, how?</p>