0
我使用eclipse,問題是我的httpConnection代碼適用於android 2.3.3。但它不適用於android 5.0我無法處理它。Android 5.0 OpenHttpConnection錯誤
private InputStream OpenHttpConnection(String urlString) throws IOException{
InputStream in = null;
int response = -1;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if(!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try{
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if(response == HttpURLConnection.HTTP_OK){
in = httpConn.getInputStream();
}
}
catch(Exception ex){
throw new IOException ("Error connecting");
}
return in;
}
它給我「錯誤連接」上的android 5.0也android 4.0.3。
這是你自己的錯誤字符串。你扔掉有價值的信息。你應該使用ex.getMessage()來獲得真正的錯誤。查看和發佈你的logcat,因爲你有更多的錯誤/例外。 – greenapps 2014-12-06 16:46:40