FileNotFoundException for HttpURLConnection in Ice Cream Sandwich
Try removing the setDoOutput call. Taken from this blog:a blog
Edit: This is needed when using a POST call.
A FileNotFoundException may also been thrown if the server returns a bad error code (e.g., 400 or 401). You can handle this as follows:
int responseCode = con.getResponseCode(); //can call this instead of con.connect()if (responseCode >= 400 && responseCode <= 499) { throw new Exception("Bad authentication status: " + responseCode); //provide a more meaningful exception message}else { InputStream in = con.getInputStream(); //etc...}
I Don't know why, but dealing manually with redirection resolves the problem.
connection.setInstanceFollowRedirects(false);