I have an Android app that works fine with Android 2.x and 3.x, but it fails when run on Android 4.x.
The problem is in this section of code:
URL url = new URL("http://blahblah.blah/somedata.xml");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
When the application is running on Android 4.x, the getInputStream()
call results in a FileNotFoundException
. When the same binary is running on earlier versions of Android, it succeeds. The URLs also work fine in web browsers and with curl
.
Apparently something about HttpURLConnection
has changed in ICS. Does anybody have any idea what has changed, and/or what the fix might be?
setDoOutput(true)
impliessetRequestMethod("POST")
. Which do you mean? – EmanatesetDoOutput(true)
was there.) – FaminesetRequestMethod("GET")
andsetDoOutput(true)
appear in a lot of sample code for usingHttpURLConnection
. Where is it documented that it forces a POST? – FamineHttpURLConnection
uses theGET
method by default. It will usePOST
ifsetDoOutput(true)
has been called. developer.android.com/reference/java/net/HttpURLConnection.html – Emanate