Try int status = conn.getResponseCode();
to see the status.
Then try InputStream error = conn.getErrorStream();
These methods are from HttpURLConnection
.
You probably get FileNotFoundException as an indication that the web server returned a 404.
This is javadoc for public InputStream getErrorStream()
:
Returns the error stream if the connection failed but the server sent
useful data nonetheless. The typical example is when an HTTP server
responds with a 404, which will cause a FileNotFoundException to be
thrown in connect, but the server sent an HTML help page with
suggestions as to what to do.
This method will not cause a connection to be initiated. If the
connection was not connected, or if the server did not have an error
while connecting or if the server had an error but no error data was
sent, this method will return null. This is the default.
Returns:
an error stream if any, null if there have been no errors, the connection is not connected or the server sent no useful data.
Also, for a case similar to yours ("I was receiving the page fine in the browser, but got a 404 when I tried to access it via the HttpURLConnection."), check this answer to see adding some request properties:
URLConnection FileNotFoundException for non-standard HTTP port sources