Example
try {
URL u = new URL(args[i]);
if (u.getPort() != -1) port = u.getPort();
if (!(u.getProtocol().equalsIgnoreCase("http"))) {
System.err.println("I only understand http.");
}
Socket s = new Socket(u.getHost(), u.getPort());
OutputStream theOutput = s.getOutputStream();
PrintWriter pw = new PrintWriter(theOutput, false);
pw.print("GET " + u.getFile() + " HTTP/1.0\r\n");
pw.print("Accept: text/plain, text/html, text/*\r\n");
pw.print("\r\n");
pw.flush();
InputStream in = s.getInputStream();
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
String theLine;
while ((theLine = br.readLine()) != null) {
System.out.println(theLine);
}
}
catch (MalformedURLException e) {
System.err.println(args[i] + " is not a valid URL");
}
catch (IOException e) {
System.err.println(e);
}