Java Reference
In-Depth Information
public static void main(String args[])
{
String strURL = "";
// obtain a URL to use
if (args.length < 1)
{
strURL = "https://www.httprecipes.com/1/5/secure/";
} else
{
strURL = args[0];
}
URL url;
try
{
url = new URL(strURL);
URLConnection conn = url.openConnection();
conn.connect();
// see what type of object was returned
if (conn instanceof HttpsURLConnection)
{
System.out.println("Valid HTTPS URL");
} else if (conn instanceof HttpURLConnection)
{
System.out.println("Valid HTTP URL");
} else
{
System.out.println("Unknown protocol URL");
}
} catch (MalformedURLException e)
{
System.out.println("Invalid URL");
} catch (IOException e)
{
System.out.println("Error connecting to URL");
}
}
}
This program can be passed a URL to access on the command line; or, if no URL is pro-
vided, the program will default to the following URL:
https://www.httprecipes.com/1/5/secure/
Search WWH ::




Custom Search