2 Minutes To Code (β Version)

Apache Commons Http Client - 2 minute tutorial

Setting proxy : How to set proxy for http hosts

This example shows how to configure HttpClient to use a proxy server to hit the http url.

The operating code here is httpClient.getHostConfiguration().setProxy(...) .
package com.techfundaes.httpBag;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;

public class SimpleGetWithProxy
{
	public static void main(String[] args)
	{
		HttpClient httpClient = new HttpClient();
		httpClient.getHostConfiguration().setProxy("202.56.254.213", 5631);
		GetMethod getMethod = new GetMethod("http://www.techfundaes.com/test.do");
		try
		{
			httpClient.executeMethod(getMethod);
			System.out.println("responseString:"+getMethod.getResponseBodyAsString());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			getMethod.releaseConnection();
		}
	}
}