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