views:

250

answers:

1

I'm trying to read a web site as an HTMLDocument; and the site requires either a cookie from a previous logon, or a response to a popup dialog. I'm thinking that supplying the necessary cookie is the easiest to accomplish, but I haven't found a way to do that. The code to open and read the document is:

URL url = new URL(suppliedURL);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
HTMLEditorKit htmlKit = new HTMLEditorKit();
HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
HTMLEditorKit.Parser parser = new ParserDelegator();
HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0);
parser.parse(br, callback, true);

The retrieved document contains incorrect information that can only be corrected by invoking a logon dialog or supplying a cookie.

So the questions are:

  1. How do I supply a cookie when opening this page?

  2. How do I copy the information from an existing IE cookie to the cookie I supply?

+3  A: 

How about using Apache Commons HttpClient.

Adeel Ansari
I don't think I can use Apache. I'm looking for a Java solution. Maybe I'm misunderstanding you.
Ken Paul
Yes, its a Java project. Did you look into it. It has some examples, and a general tutorial as well. Find the tutorial link on the left menu of that page.
Adeel Ansari
HttpClient is a library for accessing http in java - the apache you are familiar with is actually the apache httpd, or http daemon, the web server. dont get them confused.
Chii
OK - thanks -- I'll give that a try.
Ken Paul