This is the same problem as mine: HttpUrlConnection returns a FileNotFoundException if you try to read getInputStream() from the connection.
Use getErrorStream() instead if the status code is above 400.
Moreover, be careful, since not only 200 is a success status code, even 201, 204, etc. often used as success statuses.
Here is an example of how I went to manage it
... connection code code code ... // Get the response code int statusCode = connection.getResponseCode(); InputStream is = null; if (statusCode >= 200 && statusCode < 400) { // Create an InputStream in order to extract the response object is = connection.getInputStream(); } else { is = connection.getErrorStream(); } ... callback/response to your handler....
Thus, you can get the necessary answer both in case of success and in case of errors.
Hope this helps!
gpiazzese Jun 29 '15 at 18:34 2015-06-29 18:34
source share