title: How can a java program automatically follow redirection in 303 http status code response
body: <p>I tried to access <a href="http://www.wikidata.org/entity/P26" rel="nofollow noreferrer">this url</a> in my java program but I got this strange message instead of the page content as I was expecting. </p>
  
  <p>How can I avoid this?</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
  &lt;html&gt;
   &lt;head&gt; 
    &lt;title&gt;303 See Other&lt;/title&gt; 
   &lt;/head&gt;
   &lt;body&gt; 
    &lt;h1&gt;See Other&lt;/h1&gt; 
    &lt;p&gt;The answer to your request is located &lt;a href="https://www.wikidata.org/wiki/Special:EntityData/P26"&gt;here&lt;/a&gt;.&lt;/p&gt;  
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In a browser though I can navigate there easily. Is there some function or library I can use to evoke that functionality from my java program?</p>
  
  <pre><code>for (String url : list_of_relation_URLs) 
  {
      //System.out.println( url );
  
      //go to relation url
      String URL_czech = url;
  
      System.out.println( url  );
  
      URL wikidata_page = new URL(URL_czech);
      HttpURLConnection wiki_connection = (HttpURLConnection)wikidata_page.openConnection();
      InputStream wikiInputStream = null;
  
      try 
      {
          // try to connect and use the input stream
          wiki_connection.connect();
          wikiInputStream = wiki_connection.getInputStream();
      } 
      catch(IOException error) 
      {
          // failed, try using the error stream
          wikiInputStream = wiki_connection.getErrorStream();
      }
  
      // parse the input stream using Jsoup
      Document docx = Jsoup.parse(wikiInputStream, null, wikidata_page.getProtocol()+"://"+wikidata_page.getHost()+"/");
  
      System.out.println( docx.toString() );  
  }
  </code></pre>
  
  <p>I'm trying to do basically the opposite of <a href="https://stackoverflow.com/questions/2659000/java-how-to-find-the-redirected-url-of-a-url">what is going on here</a>. </p>