HttpURLConnection.getInputStream always throws IOException in android 2.1
When attempting to open a connection on the android 2.1 platform, the HttpUrlConnection.getInputStream met开发者_C百科hod always throws a IOException, FileNotFound exception. The code works as expected in 2.2 and 2.3 version of Android. I have a standard method for creating a new connection. The error is thrown immediately after this when get input stream is called. As a note, all of the connections attempting to be made are "http://something/something".
public static URLConnection createConnection(String urlStr, Boolean useAuthentication, Boolean setOutput){
Log.i(GpodRoid.LOGTAG, "Creating Connection to " + urlStr);
URLConnection conn = null;
try {
conn = new URL(urlStr).openConnection();
conn.setDoOutput(setOutput);
conn.setDoInput(true);
if(useAuthentication){
String auth = GpodRoid.prefs.getUsername() + ":" + GpodRoid.prefs.getPassword();
String encoded = Base64.encodeBytes(auth.getBytes());
conn.setRequestProperty("Authorization","basic " + encoded);
}
}
catch (Exception e) {
Log.e(GpodRoid.LOGTAG, "Error creating Connection: " + stackTrace(e));
}
return conn;
}
If it opens the connection on 2.1 - I don't see a reason why it shouldn't work on > 2.1.
Could it be a missing permission in your Android.manifest
. If yes, have you tried this ?
精彩评论