我有个问题!我有一个与数据库连接的php页面连接,该方法在Froyo上运行良好,但不适用于较新版本的Android。问题是什么?
public static String interact(String request){
String result="test";
String site = "http://xxxx.net:nnn/xxx";
URL url = new URL(site);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.connect();
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(request);
wr.flush();
wr.close();
Scanner in = new Scanner(connection.getInputStream());
while(in.hasNextLine())
result+=in.nextLine();
connection.disconnect();
return result;
}
catch (UnknownHostException e) {
return e.getMessage();
} catch (IOException ex) {
return ex.getMessage();
}
catch (Exception ex){
return ex.getMessage();
}
}
我需要发送数据并获得响应,但它只会在比 2.2 更新的 Android 上给我 null。