// This code is provided "as is" with NO WARRANTY expressed or // implied. You may use it freely at your own risk. import java.io.*; import java.net.*; public class Pete { public static void main(String[] args) { String request = "name=john&game=java&wizard_mode=on"; try { Socket socket = new Socket("www.darkspell.com", 80); InputStream response = socket.getInputStream(); PrintWriter agent = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); agent.println("POST /cgi-bin/echo.cgi HTTP/1.0"); agent.println("Content-type: application/x-www-form-urlencoded"); agent.println("Content-length: " + request.length()); agent.println(); agent.println(request); agent.flush(); byte[] buf = new byte[4096]; int bytes_read; while((bytes_read = response.read(buf)) != -1) System.out.write(buf, 0, bytes_read); System.out.println(); socket.close(); } catch(Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }