• Post Reply Bookmark Topic Watch Topic
  • New Topic

http / session cookies error  RSS feed

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a Java application that, to a degree, should act like a browser - that is, connect to particular web sites to retrieve certain content.

Additionally, sessions may need to be maintained. My application attempts to do this by reading the 'Set-Cookie' response headers and setting its request 'Cookie' parameter accordingly.

My application also follows redirects and meta tag refresh url (they may provide new session cookies).

Despite all that, I keep getting session errors thrown up by the server. Is there anything I could be missing out? I am using HttpTracer, but it isn't giving any clues.

Could I be missing anything that may affect the session status?
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using java.net, you could consider visiting here:

http://www.hccp.org/java-net-cookie-how-to.html
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satya, but I've already tried that.

I believe my application is handling the cookies fine. My question was have I overlooked anything that may affect the session/cookie status?

By that, I mean:
1. My application handles redirects (which can result in new cookies being sent)
2. My application obeys meta tag refresh commands (ditto)
3. My application also downloads embedded frames (ditto)
...but is there anything else I have missed, cos my application is getting 'Session Error' when it connects to the server?
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java HttpURLConnection class handles client-side cookies automatically and transparently. If you're explicitly setting session information or altering cookies client-side, you may be interfering with that mechanism.
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since Java 5.0 there is a class called java.net.CookieHandler which works similar to java.net.Authenticator - one application-wide CookieHandler at any given time.
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies. When I initially got the session errors, I (incorrectly) presumed HttpURLConnection didn't handle cookies. I then tried java.net.CookieManager (sub-class of java.net.CookieHandler), but I'm still getting the session errors.

Right, just found the solution! Don't know whether to laugh or cry though...
...the second url I was calling contained "& amp;" instead of "&".

I wasn't just barking up the wrong tree, I was also standing in the wrong forest!... Apologies.

url = url.replaceAll("&" + "amp;", "&");
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!