Java HTTP response code 200, while it should be 301
<p>The following code is driving me insane.  It sometimes returns the wrong response code and I do not understand why.  E.g., <code>http://www.ebay.com/itm/131709867498</code> returns a <code>301 Moved Permanently</code> in real life (Chrome and Edge), while the following code returns <code>200</code>.  Thanks a ton in advance.  (In case it matters, I am running Java 1.8.0_66.)</p>

<pre><code>HttpURLConnection connection = (HttpURLConnection)new URL("http://www.ebay.com/itm/131709867498").openConnection();

connection.setRequestMethod("HEAD");
connection.setInstanceFollowRedirects(false);

int statusCode = connection.getResponseCode();
System.out.println(statusCode);
</code></pre>