Data access via the Web
import java.util.*; import java.net.*; import java.io.*; public class testHTTP { public static void main( String argv[] ) throws IOException { String cgiscript = " http://www.gamelon.com/somedir/getinfo.cgi"; String query = null; String line = ""; query = "lname=jones&id=123"; // if your Java program is running behind the firewall and you need to // set a proxy, use the following lines // System.getProperties().put( "proxySet", "true" ); // System.getProperties().put( "proxyHost", // "proxy url goes here"); // System.getProperties().put( "proxyPort", "8000" ); try { URL url = new URL(cgiscript); URLConnection connection = url.openConnection(); connection.setDoInput( true ); connection.setDoOutput( true ); DataOutputStream output = new DataOutputStream( connection.getOutputStream() ); output.writeBytes( query ); output.close(); BufferedReader input = new BufferedReader(new InputStreamReader( connection.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); } input.close(); } catch( Exception e ) {} } }
Page 3 of 3
This article was originally published on May 25, 1999