001 package org.apache.commons.httpclient; 002 003 import org.apache.commons.httpclient.HttpClient; 004 import org.apache.commons.httpclient.methods.GetMethod; 005 import org.apache.commons.httpclient.params.HttpClientParams; 006 import org.apache.commons.httpclient.params.HttpMethodParams; 007 import org.junit.Test; 008 009 public class HttpClientTest { 010 011 @Test 012 public void test1() { 013 try { 014 String url = "http://localhost:8070"; 015 GetMethod method = new GetMethod(url); 016 HttpClient client = new HttpClient(); 017 HttpClientParams clientParams = client.getParams(); 018 HttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(0, false); 019 clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler); 020 021 int result = client.executeMethod(method); 022 Header[] headers = method.getResponseHeaders(); 023 for (Header header : headers) { 024 String name = header.getName(); 025 String value = header.getValue(); 026 System.out.println(name + "=" + value); 027 } 028 System.out.println(result); 029 } catch (Throwable t) { 030 t.printStackTrace(); 031 } 032 } 033 }