public class HttpUtil { public static void sendHttpRequest(final String address,final HttpCallbackListener listener) { if (!isNetworkAvailable()){ Toast.makeText(MyApplication.getContext(),"nonono",Toast.LENGTH_SHORT).show(); return;//通过if语句判断后,使用return后面的所有代码都不用再执行,注意只能在函数中可以使用 } new Thread(new Runnable() { @Override public void run() { HttpURLConnection connection = null; try { URL url = new URL(address); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setConnectTimeout(8000); connection.setReadTimeout(8000); InputStream inputStream = connection.getInputStream(); //下面对获取到的输入流进行读取 BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder response = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { response.append(line); } if (listener != null) { listener.onFinish(response.toString()); } } catch (Exception e) { if (listener != null) {