• Post Reply Bookmark Topic Watch Topic
  • New Topic

Who ate my cookies, issue in reading cookies  RSS feed

 
syed afzal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hidee hoo folks!

I'm try'in to read cookies from an http response. But someway cookies arent showing up no where. Please help me out with identifying the problem. Thanks !

 
Salil Wadnerkar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is always a good idea to check the HTTP status code of your request before processing the request (assuming a successful request) using conn.getResponseCode())
 
syed afzal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your input. I agree with you. I have checked the response with http://web-sniffer.net and also in my web browser . The response has set-cookie header even for a non 200 response code. I'm still not getting why its not showing in the program.
 
Salil Wadnerkar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you print all header fields, you will see that Set-Cookie is indeed empty for 4xx responses. I think the server processes the requests based on the user agent. You can try setting the user-agent to firefox/chrome and see whether you get the same response as firefox.
 
syed afzal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is snapshot from web-sniffer. Server sends cookie even for a non 200 response, without user agent header. But thats not the point, why java is not getting it ?

 
Salil Wadnerkar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, It turned out that Java processes the cookie beforehand and makes it available through CookieManager, if you have already created a CookieManager. If there is no CookieManager, the cookie is made available through the header 'Set-Cookie'. When I remove the CookieManager code, I see the cookie header.
https://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/accessingCookies.html
 
syed afzal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Thanks for clearing that out.
But still even if I remove that code and only use cookie manager, cookieJar is still empty. I dnt get it why cookie jar is not having any cookies.
 
Salil Wadnerkar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This code, after removing CookieManager related parts, does print the cookies.
 
syed afzal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your effort. I appreciate it.

So, apparently Java's cookie manager is eating my cookies.
 
Salil Wadnerkar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can just use the CookieManager. Then you don't have to parse headers yourself. Refer the oracle link I sent you in my previous post.
 
syed afzal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep used it. It didnt work.
 
Salil Wadnerkar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use conn.getContent(); for it to work. Here is the complete program that works:
 
syed afzal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well well, I'm getting "empty " and no cookies in the output when I ran the code :

 
Salil Wadnerkar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange. I get "CookieHandler retrieved cookie: __cfduid=d4470f75e409de10f73da5101f4b619921466367426"
 
syed afzal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed very strange. What it could be ? I ran the code in eclipse and in cmd. Everywhere I get "empty". Is it a bug in the Java version I'm using ?
 
syed afzal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm positive now that it is a bug in the java version I'm using.
 
syed afzal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Confirmed bug report : http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8160038
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!