View Javadoc

1   /**
2    * Copyright 2004-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }