I am trying to use the openConnect() to see if an url exist and plus check to see if there are any error code. My problem is with the check the error code I tried using the getResponseCode and got error message method getResponseCode() not found in class java.net.URLConnection. Can someone help me figure out how to use this? I attached my code:
import java.lang.Object.*;
import java.io.*;
import java.net.*;
public class URLConnTest2 {
public static void main (
String args[]) {
try {
//Url to try to connect to
URL u1 = new URL("http://199.81.168.237");
try {
//get a handle to the URLConnection object for this url
URLConnection uc = openConnection();
System.out.println("Error message " + uc.getRequestCode());
//Check whether this URL object can be "read"
if (uc.getDoInput() == true) {
//Attach an input Stream and read from this input stream
InputStream iStream = InputStream();
DataInputStream data = new iStream);
System.out.println("URL is valid");
data.close(); //close the input stream
}
} catch (IOException ie) {
System.out.println("URL is NOT valid.");
// retCode = false;
}
}catch (MalformedURLException e) {
System.out.println("Caught MUE !");
// retCode = false;
}
// return retCode;
}
}