Java Reference
In-Depth Information
The value of that cookie is then looked up. If this is not the first name-value pair written
to the StringBuilder , then append a semicolon (;) to the StringBuilder before
the next name-value pair is added. A semicolon is used to separate individual cookies.
String value = map.get(key);
if( str.length()>0 )
{
str.append("; ");
}
Next, the cookie name-value pair is appended to the StringBuilder .
str.append(key+"="+value);
}
Finally, the Cookie header is added to the URLConnection object, which is named
http .
http.setRequestProperty("Cookie", str.toString());
By using the loadCookies and saveCookies methods, you can easily add
cookie support to your bots.
Recipes
This chapter includes two recipes. These recipes demonstrate how to process a variety
of different HTML forms. Specifically, you will see how to process each of the following form
types:
• Cookieless Session
• Cookie Based Session
We will begin with the first recipe, which shows how to process a session without the use
of cookies.
Recipe #8.1: A Cookieless Session
This recipe shows how to manage a session using only the URL. No cookies are used to
maintain state. This recipe shows how to login to a simple system and perform a basic search.
This recipe will access the following URL:
http://www.httprecipes.com/1/8/cookieless.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.1.
Search WWH ::




Custom Search