Retrieving cookies from response |
To retrieve the cookies returned in an HttpResponse invoke the HttpResponse#getCookies method. This will return a java.util.Enumeration of HttpCookie. Each HttpCookie instance contains a name and value that can be retrieved by invoking the HttpCookie#getCookieName and HttpCookie#getCookieValue methods respectively.
Example
// get all cookies from response Enumeration e = response.getCookies();
// loop thru cookies printing name and value while(e.hasMoreElements()) { HttpCookie header = (HttpCookie)e.nextElement(); System.out.println("Name: " + header.getCookieName()); System.out.println("Value: " + header.getCookieValue()); } |