1 package org.apache.commons.httpclient; 2 3 import org.apache.commons.httpclient.HttpClient; 4 import org.apache.commons.httpclient.methods.GetMethod; 5 import org.apache.commons.httpclient.params.HttpClientParams; 6 import org.apache.commons.httpclient.params.HttpMethodParams; 7 import org.junit.Test; 8 9 public class HttpClientTest { 10 11 @Test 12 public void test1() { 13 try { 14 String url = "http://localhost:8070"; 15 GetMethod method = new GetMethod(url); 16 HttpClient client = new HttpClient(); 17 HttpClientParams clientParams = client.getParams(); 18 HttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(0, false); 19 clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler); 20 21 int result = client.executeMethod(method); 22 Header[] headers = method.getResponseHeaders(); 23 for (Header header : headers) { 24 String name = header.getName(); 25 String value = header.getValue(); 26 System.out.println(name + "=" + value); 27 } 28 System.out.println(result); 29 } catch (Throwable t) { 30 t.printStackTrace(); 31 } 32 } 33 }