Java: Handling cookies when logging in with POST

Posted by Cris Carter on Stack Overflow See other posts from Stack Overflow or by Cris Carter
Published on 2010-06-13T18:28:43Z Indexed on 2010/06/13 18:32 UTC
Read the original article Hit count: 394

Filed under:
|
|
|
|

I'm having quite some trouble logging in to any site in Java. I'm using the default URLconnection POST request, but I'm unsure how to handle the cookies properly. I tried this guide: http://www.hccp.org/java-net-cookie-how-to.html But couldn't get it working. I've been trying basically for days now, and I really need help if anyone wants to help me.

I'll probably be told that it's messy and that I should use a custom library meant for this stuff. I tried downloading one, but wasn't sure how to get it set up and working. I've been trying various things for hours now, and it just won't work. I'd rather do this with a standard URLconnection, but if anyone can help me get another library working that's better for this, that would be great, too.

I would really appreciate if someone could post a working source that I could study. What I need is: POST login data to site -> Get and store the cookie from the site -> use cookie with next URLconnection requests to get logged-in version of the site.

Can anyone help me with this? Would be EXTREMELY appreciated. It really does mean a lot. If anyone wants to actually help me out live, please leave an instant-messenger address. Thank you a lot for your time.

© Stack Overflow or respective owner

Related posts about java

Related posts about cookies