Picking up http request cookies

Asked

Viewed 478 times

1

Good afternoon, I am having trouble picking up cookies when I make an http request for a particular address. Using firefox+firebug I see 5 cookies. Already through my Java program I can only see 1 of them.

follows the code of the program:

public static void getCookieUsingCookieManager(String urlS) {
    try {
        CookieManager manager = new CookieManager();
        manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
        CookieHandler.setDefault(manager);

        URL url = new URL(urlS);
        URLConnection connection = url.openConnection();

        connection.getContent();

        CookieStore cookieJar = manager.getCookieStore();
        List<HttpCookie> cookies
                = cookieJar.getCookies();
        for (HttpCookie cookie : cookies) {
            System.out.println("CookieHandler retrieved cookie: " + cookie.toString());
        }
    } catch (Exception e) {
        System.out.println("Unable to get cookie using CookieHandler");
        e.printStackTrace();
    }
}
  • You do not have access to the javax.servlet.http.Httpservletrequest? object, it has the getCookies method that returns an array of javax.servlet.http.Cookie

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.