[ale] OT: Java and Cookies

Denny Chambers dchambers at bugfixer.net
Fri Aug 29 14:18:21 EDT 2003


Hey, It just so happens I am working on HttpURLConnection stuff right 
now. It sounds like the page that returns the frame sets does not return 
a Set-Cookie, but frame source URLs do return cookies. Is this correct?

I am not sure how the HttpURLConnection works with frames. Does it try 
to download each frame URL automatically? If so what you need are those 
URLConnections. From looking at your code what your looking for is a 
Set-Cookie header from the response that is returning the FrameSet HTML 
code, if that code does not send a cookie, you will not get one looking 
at that response data. If the HttpURLConnection is automatically making 
the request for all of the frame src, then that is telling me that the 
HttpURLConnection has a ContentHandler class that is parsing the html 
data, and making the necessary request. If that is true, then your 
answer may be in the ContentHandler class.

HTH,
Denny



>I'm trying to do a POST and grab a cookie to be used for later 
>authentication. I hope that maybe you guys have done this
>before.  The aut.asp page is a simple POST form.  When the
>form is submitted it returns a frameset and a cookie.  I can
>not seem to get the the HttpURLConnection to get the cookie.  It
>seems that the conneciton does the post and then tries to
>receive each page of the framset.  However, I do not see
>and Cookies: being sent with those GET requests.  Is there a
>way to get this code to use the Set-Cookie that is being sent
>back.   
>
>---------- Cut Here --------------------------------
>
>    public static void main(String args[]) {
>        InputStream is;
>        int data;
>        String s;
>        DataOutputStream    printout;
>        String c;
>        try {
>            URL url = new URL("http://127.0.0.1/auth.asp");
>            HttpURLConnection connection = (HttpURLConnection)u.openConnection();
>            String emit = "login=super&password=smart&action_login=Login";
>            connection.setRequestProperty("Content-Length", "" + emit.length());
>            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
>            connection.setUseCaches (false);
>            connection.setDoInput(true);
>            connection.setDoOutput(true);
>            connection.setFollowRedirects(false);
>            /* Not used now
>            connection.setRequestProperty(
>                "Authorization", 
>                "Basic " + "cm9vdDpwYXNzd29yZA=="
>            );      
>            */
>            connection.setDoOutput(true);
>            connection.setDoInput(true);
>            printout = new DataOutputStream (connection.getOutputStream ());
>            printout.writeBytes (emit);
>            printout.flush ();
>            printout.close ();
>            c = connection.getHeaderField("Set-Cookie");
>            System.out.println("Cookie: " + c);
>            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
>            System.out.flush();
>            while((s = br.readLine()) != null) {
>                System.out.println(s);
>            }
>        } catch (Exception Exp) {
>            System.err.println("Error: " + Exp.getMessage());
>            System.exit(1);
>        }
>    }
>
>
>---------- Cut Here --------------------------------
>_______________________________________________
>Ale mailing list
>Ale at ale.org
>http://www.ale.org/mailman/listinfo/ale
>
>
>  
>

 S/MIME Cryptographic Signature




More information about the Ale mailing list