[ale] OT: Java and Cookies
Christopher Fowler
cfowler at outpostsentinel.com
Fri Aug 29 14:02:35 EDT 2003
Here is the results of just seeing what comes back after I
dump the headers and data to the webserver:
[cfowler at cfowler tmp]$ java Soc
HTTP/1.1 302 Redirect
Server: GoAhead-Webs
Date: Sun Nov 24 18:56:24 1929
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Set-Cookie: pp_session_id=5CD7B1CFC4235F46FDDEEACC90BAD798E08780982E1E2E1E333198327F8C3B37; path=/
P3P: CP="NON DSP CURa OUR NOR UNI"
Location: http://127.0.0.1/home.asp
<html><head></head><body>
Moved to this location.
<!-- response_code_begin ERIC_RESPONSE_OK response_code_end response_msg_begin response_msg_end --></body></html>
On Fri, Aug 29, 2003 at 01:47:20PM -0400, Christopher Fowler wrote:
>
>
> 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
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list