Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 59951 invoked from network); 1 Feb 2003 18:46:20 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 1 Feb 2003 18:46:20 -0000 Received: (qmail 2761 invoked by uid 97); 1 Feb 2003 18:47:50 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 2754 invoked from network); 1 Feb 2003 18:47:50 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 1 Feb 2003 18:47:50 -0000 Received: (qmail 59762 invoked by uid 500); 1 Feb 2003 18:46:17 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 59673 invoked by uid 500); 1 Feb 2003 18:46:16 -0000 Received: (qmail 59652 invoked from network); 1 Feb 2003 18:46:16 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 1 Feb 2003 18:46:16 -0000 Received: (qmail 35778 invoked by uid 1536); 1 Feb 2003 18:46:13 -0000 Date: 1 Feb 2003 18:46:13 -0000 Message-ID: <20030201184613.35777.qmail@icarus.apache.org> From: jsdever@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/httpclient/src/examples TrivialApp.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N jsdever 2003/02/01 10:46:11 Modified: httpclient/src/examples TrivialApp.java Log: Update to make simpler. Revision Changes Path 1.8 +30 -39 jakarta-commons/httpclient/src/examples/TrivialApp.java Index: TrivialApp.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/TrivialApp.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- TrivialApp.java 23 Jan 2003 22:47:42 -0000 1.7 +++ TrivialApp.java 1 Feb 2003 18:46:11 -0000 1.8 @@ -2,6 +2,7 @@ * $Header$ * $Revision$ * $Date$ + * * ==================================================================== * * The Apache Software License, Version 1.1 @@ -104,15 +105,6 @@ System.exit(-1); } - URL url = null; - try { - url = new URL(args[0]); - } catch (MalformedURLException murle) { - System.out.println(" argument '" + url - + "' is not a valid URL"); - System.exit(-2); - } - Credentials creds = null; if (args.length >= 3) { creds = new UsernamePasswordCredentials(args[1], args[2]); @@ -129,29 +121,24 @@ client.getState().setCredentials(null, creds); } - // - HostConfiguration hc = new HostConfiguration(); - try { - hc.setHost(new URI(url)); - } catch(URIException e) { - throw new RuntimeException(e.toString()); - } - - //start a session with the webserver - client.setHostConfiguration(hc); + String url = args[0]; + HttpMethod method = null; //create a method object - HttpMethod method = new GetMethod(url.getPath()); - - //turn follow redirects off - method.setFollowRedirects(false); - - //turn strict mode on - method.setStrictMode(false); + method = new GetMethod(url); + method.setFollowRedirects(true); + method.setStrictMode(false); + //} catch (MalformedURLException murle) { + // System.out.println(" argument '" + url + // + "' is not a valid URL"); + // System.exit(-2); + //} //execute the method + String responseBody = null; try{ client.executeMethod(method); + responseBody = method.getResponseBodyAsString(); } catch (HttpException he) { System.err.println("Http error connecting to '" + url + "'"); System.err.println(he.getMessage()); @@ -161,27 +148,31 @@ System.exit(-3); } - //get the request headers - Header[] requestHeaders = method.getRequestHeaders(); - - //get the response headers - Header[] responseHeaders = method.getResponseHeaders(); - - //get the response body - byte[] responseBody = method.getResponseBody(); //write out the request headers - System.out.println("*** Request Headers ***"); + System.out.println("*** Request ***"); + System.out.println("Request Path: " + method.getPath()); + System.out.println("Request Path: " + method.getQueryString()); + Header[] requestHeaders = method.getRequestHeaders(); for (int i=0; i