Java Reference
In-Depth Information
Table 8.1: Extracting from Cookieless Session
Step
Function
Step 1.
Post login information to http://www.httprecipes.com/1/8/cookieless.php
Step 2:
Extract session id from http://www.httprecipes.com/1/8/menunc.
php?session=[Session id]
Step 3.
Be redirected to Post search to http://www.httprecipes.com/1/8/menunc.
php?session=[Session id]
Step 4.
Parse search results
This recipe is shown in Listing 8.2.
Listing 8.2: Cookieless Session (Cookieless.java)
package com.heatonresearch.httprecipes.ch8.recipe1;
import java.io.*;
import java.net.*;
import java.util.*;
import com.heatonresearch.httprecipes.html.*;
public class Cookieless
{
/**
* This method is called to log into the system and return
* a session id. Once you have the session ID you can call
* the search function to perform searches.
* @param uid The user id to use for login.
* @param pwd The password to use for login.
* @return The session id if login was successful, null if
* it was not.
* @throws IOException If an exception occurs while reading.
*/
private String login(String uid, String pwd) throws IOException
{
URL url =
new URL("http://www.httprecipes.com/1/8/cookieless.php");
URLConnection http = url.openConnection();
http.setDoOutput(true);
OutputStream os = http.getOutputStream();
FormUtility form = new FormUtility(os, null);
form.add("uid", uid);
form.add("pwd", pwd);
form.add("action", "Login");
Search WWH ::




Custom Search