Java Reference
In-Depth Information
Listing 8.1: Cookie Utility (CookieUtility.java)
package com.heatonresearch.httprecipes.html;
import java.net.*;
import java.util.*;
public class CookieUtility
{
/*
* Map that holds all of the cookie values.
*/
private Map<String, String> map = new HashMap<String, String>();
/**
* Allows access to the name/value pair list of cookies.
*
* @return the map
*/
public Map<String, String> getMap()
{
return this.map;
}
/**
* Load any cookies from the specified URLConnection
* object. Cookies will be located by their Set-Cookie
* headers. Any cookies that are found can be moved to a
* new URLConnection class by calling saveCookies.
*
* @param http
* The URLConnection object to load the cookies
* from.
*/
public void loadCookies(URLConnection http)
{
String str;
int n = 1;
do
{
str = http.getHeaderFieldKey(n);
if ((str != null) && str.equalsIgnoreCase("Set-Cookie"))
{
str = http.getHeaderField(n);
Search WWH ::




Custom Search