@Test public void testConnection(){ try { String content = JGet.wget("http: Assert.assertFalse(content.isEmpty()); } catch (Exception e) { e.printStackTrace(); Assert.fail("Could not connect to google.com"); } }
public static String wget(String url, int connectTimeout, int readTimeout) throws MalformedURLException, IOException { StringBuilder content = new StringBuilder(); String s; URL u = new URL(url); HttpURLConnection huc = (HttpURLConnection) u.openConnection(); HttpURLConnection.setFollowRedirects(false); huc.setConnectTimeout(connectTimeout); huc.setReadTimeout(readTimeout); huc.setRequestMethod("GET"); huc.connect(); InputStream is = huc.getInputStream(); BufferedReader dis = new BufferedReader(new InputStreamReader(is)); while ((s = dis.readLine()) != null) { content.append(s).append("\n"); } return content.toString(); }
JGet { public static String wget(String url, int connectTimeout, int readTimeout) throws MalformedURLException, IOException { StringBuilder content = new StringBuilder(); String s; URL u = new URL(url); HttpURLConnection huc = (HttpURLConnection) u.openConnection(); HttpURLConnection.setFollowRedirects(false); huc.setConnectTimeout(connectTimeout); huc.setReadTimeout(readTimeout); huc.setRequestMethod("GET"); huc.connect(); InputStream is = huc.getInputStream(); BufferedReader dis = new BufferedReader(new InputStreamReader(is)); while ((s = dis.readLine()) != null) { content.append(s).append("\n"); } return content.toString(); } }
JGet { public static String wget(String url, int connectTimeout, int readTimeout) throws MalformedURLException, IOException { StringBuilder content = new StringBuilder(); String s; URL u = new URL(url); HttpURLConnection huc = (HttpURLConnection) u.openConnection(); HttpURLConnection.setFollowRedirects(false); huc.setConnectTimeout(connectTimeout); huc.setReadTimeout(readTimeout); huc.setRequestMethod("GET"); huc.connect(); InputStream is = huc.getInputStream(); BufferedReader dis = new BufferedReader(new InputStreamReader(is)); while ((s = dis.readLine()) != null) { content.append(s).append("\n"); } return content.toString(); }  }
JGet { public static String wget(String url, int connectTimeout, int readTimeout) throws MalformedURLException, IOException { StringBuilder content = new StringBuilder(); String s; URL u = new URL(url); HttpURLConnection huc = (HttpURLConnection) u.openConnection(); HttpURLConnection.setFollowRedirects(false); huc.setConnectTimeout(connectTimeout); huc.setReadTimeout(readTimeout); huc.setRequestMethod("GET"); huc.connect(); InputStream is = huc.getInputStream(); BufferedReader dis = new BufferedReader(new InputStreamReader(is)); while ((s = dis.readLine()) != null) { content.append(s).append("\n"); } return content.toString(); }  static String wget(String url, int connectTimeout, int readTimeout); }
JGet { public static String wget(String url, int connectTimeout, int readTimeout) throws MalformedURLException, IOException { StringBuilder content = new StringBuilder(); String s; URL u = new URL(url); HttpURLConnection huc = (HttpURLConnection) u.openConnection(); HttpURLConnection.setFollowRedirects(false); huc.setConnectTimeout(connectTimeout); huc.setReadTimeout(readTimeout); huc.setRequestMethod("GET"); huc.connect(); InputStream is = huc.getInputStream(); BufferedReader dis = new BufferedReader(new InputStreamReader(is)); while ((s = dis.readLine()) != null) { content.append(s).append("\n"); } return content.toString(); }  static String wget(String url, int connectTimeout, int readTimeout);  }