FileDocCategorySizeDatePackage
RedirectExample.javaAPI DocExample2464Wed May 18 09:39:00 BST 2005com.discursive.jccook.httpclient

RedirectExample

public class RedirectExample extends Object

Fields Summary
Constructors Summary
Methods Summary
private static voidexecuteMethod(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.HttpMethod method)

		client.executeMethod( method );
		System.out.println( "Response Code: " + method.getStatusCode() );
		String response = method.getResponseBodyAsString();
		System.out.println( response );
		method.releaseConnection();
		method.recycle();
	
public static voidmain(java.lang.String[] args)

		// Configure Logging
		System.setProperty("org.apache.commons.logging.Log", 
			"org.apache.commons.logging.impl.SimpleLog");
		System.setProperty("org.apache.commons.logging.simplelog.showdatetime", 
			"true");
		System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", 
			"debug");
		System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", 
			"debug");

		HttpClient client = new HttpClient();
		String url = "http://www.discursive.com/cgi-bin/jccook/redirect.cgi";
	
		System.out.println( "Executing Method not following redirects: ");		
		HttpMethod method = new GetMethod( url );
		method.setFollowRedirects( false );
		executeMethod(client, method);

		System.out.println( "Executing Method following redirects: ");		
		method = new GetMethod( url );
		method.setFollowRedirects( true );
		executeMethod(client, method);