/* Need http://hc.apache.org/downloads.cgi Depends http://commons.apache.org/downloads/download_logging.cgi http://commons.apache.org/downloads/download_codec.cgi http://www.junit.org/ -> ? */ import java.io.*; import java.util.*; import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.cookie.*; import org.apache.commons.httpclient.methods.*; import static org.apache.commons.httpclient.cookie.CookiePolicy.BROWSER_COMPATIBILITY; public class HttpClient01 { public static void main(String args[]) { HttpClient client = new HttpClient(); for (int i = 0; i < 3; i++) { HttpMethod method = new GetMethod(args[0]); method.getParams().setCookiePolicy(BROWSER_COMPATIBILITY); try { int statusCode = client.executeMethod(method); Cookie[] cookies = client.getState().getCookies(); System.out.println("===== Cookies ====="); for(Cookie cookie: cookies) { System.out.println(cookie); } System.out.println("===== Body ====="); String responseBody = method.getResponseBodyAsString(); System.out.println(responseBody); } catch (HttpException he) { he.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { method.releaseConnection(); } } } }