Я хочу постоянно отслеживать, активен ли сайт или нет, используя следующий код в Java:
URL url1 = new URL ("http://www.google.com");
HttpURLConnection code = (HttpURLConnection)url1.openConnection();
System.out.println(code.getResponseCode());
но я получаю сообщение об ошибке:
Exception in thread "main" java.net.UnknownHostException: www.google.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:158)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at sun.net.NetworkClient.doConnect(NetworkClient.java:178)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:409)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:240)
at sun.net.www.http.HttpClient.New(HttpClient.java:321)
at sun.net.www.http.HttpClient.New(HttpClient.java:338)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:935)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:876)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:801)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1139)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:397)
at java.net.HttpURLConnection.getResponseMessage(HttpURLConnection.java:463)
Я что-то не так делаю? Пожалуйста посоветуй.
Спасибо.