Java Reference
In-Depth Information
} else
{
If we are between an <li> and </li> tag, then we should be capturing text - since
this is a list item, and our data is contained in the list items.
if (capture)
buffer.append((char) ch);
}
}
return result;
Finally, the list of states is returned.
Recipe #8.2: A Cookie Based Session
This recipe shows how to manage a session using cookies. Cookies are used to maintain
state. This recipe shows how to login to a simple system and perform a basic search, which is
the same as Recipe 8.1, except cookies are used. This recipe will access the following URL:
http://www.httprecipes.com/1/8/cookie.php
This recipe must go through several steps to get the data requested. First, it must login
to the system and obtain a session. Next, it must submit the search. Finally, it must parse the
results of the search. These steps are summarized in Table 8.2.
Table 8.2: Extracting from Cookie Based Session
Step
Function
Step 1.
Post login information to http://www.httprecipes.com/1/8/cookieless.php
Step 2:
Extract session id from the headers returned, look for the Set-Cookie
header.
Step 3.
Be redirected to Post search to http://www.httprecipes.com/1/8/menu.php
use the cookie
Step 4.
Parse search results
This recipe is shown in Listing 8.3.
Listing 8.3: Cookie-Based Session (Cookie.java)
package com.heatonresearch.httprecipes.ch8.recipe2;
import java.io.*;
import java.net.*;
Search WWH ::




Custom Search