String url="https://www.baidu.com/";
html = new URL(url); HttpURLConnection connection = (HttpURLConnection) html.openConnection(); connection.setRequestMethod("GET"); connection.setDoInput(true); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); if(connection.getResponseCode()==200) { InputStream is = connection.getInputStream(); // Toast.makeText(MainActivity. this,connection.getInputStream().toString(),Toast.LENGTH_LONG); }
html = new URL(url); HttpURLConnection connection = (HttpURLConnection) html.openConnection(); connection.setRequestMethod("GET"); connection.setDoInput(true); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); if(connection.getResponseCode()==200) { InputStream is = connection.getInputStream(); // Toast.makeText(MainActivity. this,connection.getInputStream().toString(),Toast.LENGTH_LONG); }
新开线程,这里有我自己封装的网络请求回调工具
可以试试这个