FileDocCategorySizeDatePackage
QueryStringExample.javaAPI DocExample2366Wed May 18 09:39:00 BST 2005com.discursive.jccook.httpclient

QueryStringExample

public class QueryStringExample extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		HttpClient client = new HttpClient();

		String url = "http://www.discursive.com/cgi-bin/jccook/param_list.cgi";

		// Set the Query String with setQueryString()
		HttpMethod method = new GetMethod( url );
		method.setQueryString( URIUtil.encodeQuery( "test1=O'Reilly&blah=Whoop" ) );
		System.out.println( "With Query String: " + method.getURI() );
		client.executeMethod( method );
		System.out.println( "Response:\n " + method.getResponseBodyAsString() );
		method.releaseConnection();
		
		// Set query string with name value pair objects
		method = new GetMethod( url );
		NameValuePair pair = new NameValuePair( "test2", URIUtil.encodeQuery( "One & Two" ) );
		NameValuePair pair2 = new NameValuePair( "param2", URIUtil.encodeQuery( "TSCM" ) );
		NameValuePair[] pairs = new NameValuePair[] { pair, pair2 };
		method.setQueryString( pairs );
		System.out.println( "With NameValuePairs: " + method.getURI() );
		client.executeMethod( method );
		System.out.println( "Response:\n " + method.getResponseBodyAsString() );
		method.releaseConnection();