user3112115
user3112115

Reputation: 715

Java cookie not adding to browser

            CookieManager manager = new CookieManager();
            CookieHandler.setDefault(manager);
            CookieStore cookieJar =  manager.getCookieStore();

            // create cookie
            HttpCookie cookie = new HttpCookie("UserName", "John Doe");

            // add cookie to CookieStore for a
            // particular URL
            URL url = new URL("http://localhost");
            cookieJar.add(url.toURI(), cookie);

As I'v readed this code adds a cookie to the browser with every http request, but I've checked the browser cookies, and there's no UserName what is missing in this code?

Upvotes: 0

Views: 256

Answers (1)

Stephan
Stephan

Reputation: 43083

As I'v readed this code adds a cookie to the browser

Not the browser but to the requests made by Java when your code use a url. When you'll do url.openConnection() the cookie will be added.

Upvotes: 2

Related Questions