001 /**
002 * Copyright 2004-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.apache.commons.httpclient;
017
018 import org.apache.commons.httpclient.HttpClient;
019 import org.apache.commons.httpclient.methods.GetMethod;
020 import org.apache.commons.httpclient.params.HttpClientParams;
021 import org.apache.commons.httpclient.params.HttpMethodParams;
022 import org.junit.Test;
023
024 public class HttpClientTest {
025
026 @Test
027 public void test1() {
028 try {
029 String url = "http://localhost:8070";
030 GetMethod method = new GetMethod(url);
031 HttpClient client = new HttpClient();
032 HttpClientParams clientParams = client.getParams();
033 HttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(0, false);
034 clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler);
035
036 int result = client.executeMethod(method);
037 Header[] headers = method.getResponseHeaders();
038 for (Header header : headers) {
039 String name = header.getName();
040 String value = header.getValue();
041 System.out.println(name + "=" + value);
042 }
043 System.out.println(result);
044 } catch (Throwable t) {
045 t.printStackTrace();
046 }
047 }
048 }