import org.apache.commons.httpclient.HttpException; /** \file * * Oct 23, 2004 * * Copyright Ian Kaplan 2004, Bear Products International * * You may use this code for any purpose, without restriction, * including in proprietary code for which you charge a fee. * In using this code you acknowledge that you understand its * function completely and accept all risk in its use. * * @author Ian Kaplan, www.bearcave.com, iank@bearcave.com */ /** * HttpClient * Oct 23, 2004 * * @author Ian Kaplan, www.bearcave.com, iank@bearcave.com */ public class HttpClient { public static void main(String[] args) { final String url = "http://localhost:8080/test/echo"; // test for HTTP timeout: final String url = "http://128.168.1.101/test/echo"; final int timeout = 30 /* seconds */ * 1000 /* msec */; HttpPostMessage post = new HttpPostMessage( url, timeout ); try { for (int i = 0; i < args.length; i++) { String rslt = post.postMessage( args[i] ); if (rslt != null) { System.out.println(rslt); } else { System.out.println("rslt is null"); } } // for } catch (HttpException e) { Exception ex = (Exception) e.getCause(); System.out.print( e.getMessage() ); if (ex != null) { System.out.println(" : " + ex); ex.printStackTrace(); } else { System.out.println(); } } } }