// File: IO25.java (Module 13) // // Author: Rahul Simha // Created: Nov 30, 1998 // // Using HTTP POST import java.net.*; import java.io.*; public class IO15 { public static void main (String[] argv) { try { Socket soc = new Socket ("search.yahoo.com", 80); InetAddress remoteMachine = soc.getInetAddress(); System.out.println ("Attempting connection to " + remoteMachine); // Now create the output and input streams OutputStream outStream = soc.getOutputStream (); PrintWriter pw = new PrintWriter (outStream); InputStream inStream = soc.getInputStream(); InputStreamReader isr = new InputStreamReader (inStream); LineNumberReader lnr = new LineNumberReader (isr); // Get the page. pw.print ("POST /bin/search?\n"); pw.print ("Content-type: plain/text\n"); pw.print ("Content-length: 100\n"); pw.print ("p=java"); pw.print ("\n\n"); pw.flush (); String s = lnr.readLine (); while (s != null) { System.out.println (s); s = lnr.readLine (); } pw.close (); lnr.close (); soc.close (); } catch (IOException e) { System.out.println (e); } } }