Java Reference
In-Depth Information
import java.util.*;
import com.heatonresearch.httprecipes.html.*;
public class Cookie
{
/*
* Holds the cookies used to keep the session.
*/
private CookieUtility cookies = new CookieUtility();
/**
* This method is called to log into the system and establish
* the cookie. Once the cookie is established, 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 True if the login was successful.
* @throws IOException If an exception occurs while reading.
*/
private boolean login(String uid, String pwd) throws IOException
{
URL url = new URL(
"http://www.httprecipes.com/1/8/cookie.php");
HttpURLConnection http =
(HttpURLConnection) url.openConnection();
http.setInstanceFollowRedirects(false);
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");
form.complete();
http.getInputStream();
cookies.loadCookies(http);
return (cookies.getMap().containsKey("hri-cookie"));
}
/** Advance to the specified HTML tag.
* @param parse The HTML parse object to use.
* @param tag The HTML tag.
* @param count How many tags like this to find.
* @return True if found, false otherwise.
* @throws IOException If an exception occurs while reading.
Search WWH ::




Custom Search