public static void main(String[] args) { String url="";
Boolean flag = true; if (url == null) { flag = false; } //服务器测试确保接口可链接 try { url=172.*.*.*; //测试服务器是否可用 172.*.*.* InetAddress address = InetAddress.getByName(url); flag = address.isReachable(1500); //ip+port 172.*.*.*:1111 url=172.*.*.*:1111; Socket connect = new Socket(); url = url.replaceAll("%3A",":").replaceAll("%253A",":").replaceAll("%2F","/"); String[] splits = url.split(":"); System.out.println(splits.toString()); connect.connect(new InetSocketAddress(splits[0], Integer.parseInt(splits[1])),1000); flag=connect.isConnected(); //需要接口的路径 172.*.*.*:1111/urlAvailability url=172.*.*.*:1111/urlAvailability; url = url.replaceAll("%3A",":").replaceAll("%253A",":").replaceAll("%2F","/"); HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); if (HttpURLConnection.HTTP_OK == connection.getResponseCode()) { flag = true; } } catch (Exception e) { flag = false; }
System.out.println(flag) }