Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-03-2008, 06:07 PM
Member
 
Join Date: Feb 2008
Posts: 1
Zer0 is on a distinguished road
CookieManager doesn't send cookies?
Problem:
CookieManager stores cookies in the CookieStore after visiting urls, but it does not seem to retrieve cookies from the cookiestore when creating http requests.
It this a bug ?

To test cookies, I made a simple php page that displays and sets cookies: http://www.vitaminb5acne.com/testcookies.php

The Java HTTP client code that I use to test CookieManager:
Code:
import java.io.*; import java.net.*; import java.util.*; // Retrieves a webpage two times, print it, and print cookies public class Fetch { public static void main(String args[]) throws Exception { // Setup the cookiemanager CookieManager manager = new CookieManager(); manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); // Visit the url for the first time // (so that cookies will be added to the CookieStore afterward) System.out.println("--- First visit ---"); visitPage(); // Visit the url for second time // (So that cookies *SHOULD* be retrieved from the CookieStore // when creating the HTTP request.) System.out.println("--- Second visit ---"); visitPage(); // Print the stored cookies System.out.println("--- Printing stored cookies ---"); CookieStore cookieJar = manager.getCookieStore(); List<HttpCookie> cookies = cookieJar.getCookies(); for (HttpCookie cookie : cookies) { System.out.println("Cookie: " + cookie); } } // Visits a webpage, and prints it public static void visitPage() throws Exception { String urlString = "http://www.vitaminb5acne.com/testcookies.php"; // retrieve page URL url = new URL(urlString); URLConnection connection = url.openConnection(); Object obj = connection.getContent(); // Print webpage BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } }
Executing this code, shows that the webpage returns cookies, but that cookies aren't retrieved from the CookieStore of CookieManager when making a second HTTP request.....

Does anybody know what is going wrong?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Handling Cookies in JSP (III) JavaForums Java Blogs 0 03-31-2008 05:50 PM
Handling Cookies in JSP (II) JavaForums Java Blogs 0 03-31-2008 05:50 PM
JSP cookies example Java Tip Java Tips 0 01-15-2008 04:11 PM
Setting cookies in JSP Java Tip Java Tips 0 12-10-2007 06:33 PM
cookies question sandor New To Java 1 05-09-2007 01:29 AM


All times are GMT +3. The time now is 04:20 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org