How to concatenate path to base url when a url redirects?
<p>I'm making a request to:</p>

<p><code>http://www.baseaddress.com/path/index1.html</code></p>

<p>According to the arguments I sent, I'm getting a redirect to one of this two:
<code>http://www.baseaddress.com/path2/</code><br>
OR
<code>http://www.baseaddress.com/path/index2.html</code></p>

<p>The problem is that the respond returns only:
<code>index2.html</code> or <code>/path2/</code></p>

<p>for now I check if the first char is <code>/</code>, and concatenate the URL according to this.
Is there a simple method for doing this without string checking?</p>

<p>the code:</p>

<pre><code>url = new URL("http://www.baseaddress.com/path/index1.php");
con = (HttpURLConnection) url.openConnection();
... some settings
in = con.getInputStream();
redLoc = con.getHeaderField("Location"); // returns "index2.html" or "/path2/"
if(redLoc.startsWith("/")){
  url = new URL("http://www.baseaddress.com" + redLoc);
}else{
  url = new URL("http://www.baseaddress.com/path/" + redLoc);
}
</code></pre>

<p>do you think this is the best method?</p>
