4.7.3 Using URLs and URLConnection

Based on the Javasoft URL tutorial.

Using URL to post is relatively simple.

  1. Create a URL.
  2. Open a connection to the URL.
  3. Set output capability on the URLConnection.
  4. Get an output stream from the connection. This output stream is connected to the standard input stream of the cgi-bin script on the server. Its probably convenient to ensure that this is a PrintWriter.
  5. Write to the output stream.
  6. Close the output stream.
  7. Get the input stream from the connection.
  8. Read from the input stream, again probably easiest as a BufferedReader.

And here is an answer

Ian Wakeman 2005-02-22