Example: Using URL classes
This page underlines the basic points of URL communications.
Actual coding requires more details that can be found at
Examples: fetchURL(), urlExists(), postURL() and appletPrint()
// Fetch a document with URL
// remember that Applets restrict you to your server only
URL fileToFetch = new URL("http://www.uswest.com");
Object anHTMLPage = fileToFetch.getContent(); // return a stream object
// Send a message to HTTP
// create a URL object first
URL address = new URL("http://www.aol.com/cgi-bin/getForm.cgi");
// create URLConnection object using openConnection() method
URLConnection connector = address.openConnection();
// prepare the connection for output using setDoOutput() method
connector.setDoOutput(true);
// get output stream for the connection and write data out
DataOutputStream out = new DataOutputStream(connector.getOutputStream());
out.writeBytes("userID=jzhuk&serviceRequested=newsDelivery");
// close the output stream
out.close();