private static boolean isInternetOK(String[] urls) { System.setProperty("http.proxyHost", "192.168.0.100"); System.setProperty("http.proxyPort", "9999"); System.setProperty("https.proxyHost", "192.168.0.100"); System.setProperty("https.proxyPort", "9999"); for (String url : urls) { try { HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); urlConnection.setRequestMethod("HEAD"); urlConnection.setConnectTimeout(5000); // 设置连接超时时间为5秒钟 int statusCode = urlConnection.getResponseCode(); if (statusCode == 200) return true; } catch (Exception e) { } } return false; }
标签:通断,urlConnection,java,0.100,网络,System,9999,setProperty From: https://www.cnblogs.com/nanfei/p/17411152.html