Class CookieManager


  • public class CookieManager
    extends Object
    CookieManager is a simple utilty for handling cookies when working with java.net.URL and java.net.URLConnection objects. Cookiemanager cm = new CookieManager(); URL url = new URL("http://www.hccp.org/test/cookieTest.jsp"); . . . // getting cookies: URLConnection conn = url.openConnection(); conn.connect(); // setting cookies cm.storeCookies(conn); cm.setCookies(url.openConnection());
    • Constructor Detail

      • CookieManager

        public CookieManager()
    • Method Detail

      • addCookie

        public void addCookie​(String name,
                              String value)
      • storeCookies

        public void storeCookies​(URLConnection conn)
                          throws IOException
        Retrieves and stores cookies returned by the host on the other side of the the open java.net.URLConnection. The connection MUST have been opened using the connect() method or a IOException will be thrown.
        Parameters:
        conn - a java.net.URLConnection - must be open, or IOException will be thrown
        Throws:
        IOException - Thrown if conn is not open.
      • setCookies

        public void setCookies​(URLConnection conn)
                        throws IOException
        Prior to opening a URLConnection, calling this method will set all unexpired cookies that match the path or subpaths for thi underlying URL The connection MUST NOT have been opened method or an IOException will be thrown.
        Parameters:
        conn - a java.net.URLConnection - must NOT be open, or IOException will be thrown
        Throws:
        IOException - Thrown if conn has already been opened.
      • toString

        public String toString()
        Returns a string representation of stored cookies organized by domain.
        Overrides:
        toString in class Object
      • main

        public static void main​(String[] args)