How come HttpURLConnection.getResponseCode()
throws IOException
even if the status is known?
Caused by: java.io.IOException: Server returned HTTP response code: 412 for URL: <my url>
It's not a problem of getting the response code because it is written in the exception message.
I would expect to have an option to get the status code (even if it's not ~200) without getting an exception, so I'll be able to decide in my code what to do.
Full stack trace:
Caused by: java.io.IOException: Server returned HTTP response code: 412 for URL: <my url>
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1625)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
... my code
UPDATE I changed the server side implementation to return a different status code (303), and it's working now (not throwing IOException). Meaning it is specifically related to 412.