olegk 2003/02/19 06:53:02 Modified: httpclient/src/examples CookieDemoApp.java Log: Cookie demo app updated to explicitly set cookie management policy Contributed by Oleg Kalnichevski Revision Changes Path 1.9 +19 -4 jakarta-commons/httpclient/src/examples/CookieDemoApp.java Index: CookieDemoApp.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/CookieDemoApp.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- CookieDemoApp.java 19 Feb 2003 14:23:08 -0000 1.8 +++ CookieDemoApp.java 19 Feb 2003 14:53:02 -0000 1.9 @@ -61,6 +61,7 @@ */ import org.apache.commons.httpclient.*; +import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.methods.*; import java.io.*; import java.net.URL; @@ -107,6 +108,20 @@ Cookie mycookie = new Cookie(".foobar.com", "mycookie", "stuff", "/", null, false); // and then added to your HTTP state instance initialState.addCookie(mycookie); + // RFC 2101 cookie management spec is used per default + // to parse, validate, format & match cookies + initialState.setCookiePolicy(CookiePolicy.RFC2109); + // A different cookie management spec can be selected + // when desired + +// initialState.setCookiePolicy(CookiePolicy.NETSCAPE_DRAFT); + // Netscape Cookie Draft spec is provided for completeness + // You would hardly want to use this spec in real life situations +// initialState.setCookiePolicy(CookiePolicy.COMPATIBILITY); + // Compatibility policy is provided in order to mimic cookie + // management of popular web browsers that is in some areas + // not 100% standards compliant + // Get HTTP client instance HttpClient httpclient = new HttpClient(); httpclient.setConnectionTimeout(30000); @@ -122,7 +137,7 @@ // Display the cookies System.out.println("Present cookies: "); for (int i = 0; i < cookies.length; i++) { - System.out.println(cookies[i].toExternalForm()); + System.out.println(" - " + cookies[i].toExternalForm()); } // Release current connection to the connection pool once you are done httpget.releaseConnection();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]