I've a local server which runs on http://192.168.0.101:8080/. Whenver I try to ping the server using following code I get response code as "401". My server requires password as "12345"
try {
URL url = new URL("http://192.168.0.101:8080/");
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
urlc.setRequestMethod("GET");
urlc.setConnectTimeout(10 * 1000); // 10 s.
urlc.connect();
System.out.println("code" + urlc.getResponseCode());
if (urlc.getResponseCode() == 200) { // 200 = "OK" code (http connection is fine).
System.out.println("Connection success");
} else {
System.out.println("Connection nada");
}
} catch (MalformedURLException e1) {
System.out.println("MalformedURLException");
} catch (IOException e) {
System.out.println("IOException nada");
}