Http
private String getHttpValue() { String str=""; String url = "http://test"; URL getUrl; HttpURLConnection connection; try { getUrl = new URL(url); connection = (HttpURLConnection) getUrl.openConnection(); connection.connect(); BufferedReader reader = new BufferedReader(new InputStreamReader( connection.getInputStream())); String lines; while ((lines = reader.readLine()) != null) { str+=lines; } reader.close(); connection.disconnect(); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println("请求返回内容:\n" + str.toString()); if (str != "") { try { JSONObject jsonObject = new JSONObject(str); str = jsonObject.getString("key"); } catch (Exception e) { Log.e(TAG, e.toString()); } } return str; }