CookieStore
Stay organized with collections
Save and categorize content based on your preferences.
A CookieStore object represents a storage for cookie. Can store and retrieve
cookies.
CookieManager
will call CookieStore.add
to save cookies
for every incoming HTTP response, and call CookieStore.get
to
retrieve cookie for every outgoing HTTP request. A CookieStore
is responsible for removing HttpCookie instances which have expired.
Public Method Summary
abstract
void
|
|
abstract
List<HttpCookie>
|
get( URI uri)
Retrieve cookies associated with given URI, or whose domain matches the
given URI.
|
abstract
List<HttpCookie>
|
getCookies()
Get all not-expired cookies in cookie store.
|
abstract
List<URI>
|
getURIs()
Get all URIs which identify the cookies in this cookie store.
|
abstract
boolean
|
|
abstract
boolean
|
removeAll()
Remove all cookies in this cookie store.
|
Public Methods
public
abstract
void
add
(URI uri, HttpCookie cookie)
Adds one HTTP cookie to the store. This is called for every
incoming HTTP response.
A cookie to store may or may not be associated with an URI. If it
is not associated with an URI, the cookie's domain and path attribute
will indicate where it comes from. If it is associated with an URI and
its domain and path attribute are not specified, given URI will indicate
where this cookie comes from.
If a cookie corresponding to the given URI already exists,
then it is replaced with the new one.
Parameters
uri |
the uri this cookie associated with.
if null , this cookie will not be associated
with an URI |
cookie |
the cookie to store |
Retrieve cookies associated with given URI, or whose domain matches the
given URI. Only cookies that have not expired are returned.
This is called for every outgoing HTTP request.
Parameters
uri |
the uri associated with the cookies to be returned |
Returns
- an immutable list of HttpCookie,
return empty list if no cookies match the given URI
public
abstract
List<HttpCookie>
getCookies
()
Get all not-expired cookies in cookie store.
Returns
- an immutable list of http cookies;
return empty list if there's no http cookie in store
public
abstract
List<URI>
getURIs
()
Get all URIs which identify the cookies in this cookie store.
Returns
- an immutable list of URIs;
return empty list if no cookie in this cookie store
is associated with an URI
public
abstract
boolean
remove
(URI uri, HttpCookie cookie)
Remove a cookie from store.
Parameters
uri |
the uri this cookie associated with.
if null , the cookie to be removed is not associated
with an URI when added; if not null , the cookie
to be removed is associated with the given URI when added. |
cookie |
the cookie to remove |
Returns
true
if this store contained the specified cookie
public
abstract
boolean
removeAll
()
Remove all cookies in this cookie store.
Returns
true
if this store changed as a result of the call
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eCookieStore\u003c/code\u003e provides an interface for storing and retrieving HTTP cookies.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eCookieManager\u003c/code\u003e utilizes \u003ccode\u003eCookieStore\u003c/code\u003e to manage cookies for HTTP requests and responses.\u003c/p\u003e\n"],["\u003cp\u003eCookies can be associated with a URI or have their domain and path specified.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eCookieStore\u003c/code\u003e offers methods to add, retrieve, and remove cookies, as well as to get all cookies or URIs.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eCookieStore\u003c/code\u003e automatically handles the removal of expired cookies.\u003c/p\u003e\n"]]],[],null,["public interface **CookieStore** \nA CookieStore object represents a storage for cookie. Can store and retrieve\ncookies.\n\n[CookieManager](../../../reference/java/net/CookieManager.html) will call `CookieStore.add` to save cookies\nfor every incoming HTTP response, and call `CookieStore.get` to\nretrieve cookie for every outgoing HTTP request. A CookieStore\nis responsible for removing HttpCookie instances which have expired. \n\nPublic Method Summary\n\n|----------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [add](../../../reference/java/net/CookieStore.html#add(java.net.URI,%20java.net.HttpCookie))([URI](../../../reference/java/net/URI.html) uri, [HttpCookie](../../../reference/java/net/HttpCookie.html) cookie) Adds one HTTP cookie to the store. |\n| abstract [List](../../../reference/java/util/List.html)\\\u003c[HttpCookie](../../../reference/java/net/HttpCookie.html)\\\u003e | [get](../../../reference/java/net/CookieStore.html#get(java.net.URI))([URI](../../../reference/java/net/URI.html) uri) Retrieve cookies associated with given URI, or whose domain matches the given URI. |\n| abstract [List](../../../reference/java/util/List.html)\\\u003c[HttpCookie](../../../reference/java/net/HttpCookie.html)\\\u003e | [getCookies](../../../reference/java/net/CookieStore.html#getCookies())() Get all not-expired cookies in cookie store. |\n| abstract [List](../../../reference/java/util/List.html)\\\u003c[URI](../../../reference/java/net/URI.html)\\\u003e | [getURIs](../../../reference/java/net/CookieStore.html#getURIs())() Get all URIs which identify the cookies in this cookie store. |\n| abstract boolean | [remove](../../../reference/java/net/CookieStore.html#remove(java.net.URI,%20java.net.HttpCookie))([URI](../../../reference/java/net/URI.html) uri, [HttpCookie](../../../reference/java/net/HttpCookie.html) cookie) Remove a cookie from store. |\n| abstract boolean | [removeAll](../../../reference/java/net/CookieStore.html#removeAll())() Remove all cookies in this cookie store. |\n\nPublic Methods \n\npublic abstract void\n**add**\n([URI](../../../reference/java/net/URI.html) uri, [HttpCookie](../../../reference/java/net/HttpCookie.html) cookie) \nAdds one HTTP cookie to the store. This is called for every\nincoming HTTP response.\n\nA cookie to store may or may not be associated with an URI. If it\nis not associated with an URI, the cookie's domain and path attribute\nwill indicate where it comes from. If it is associated with an URI and\nits domain and path attribute are not specified, given URI will indicate\nwhere this cookie comes from.\n\nIf a cookie corresponding to the given URI already exists,\nthen it is replaced with the new one. \n\nParameters\n\n| uri | the uri this cookie associated with. if `null`, this cookie will not be associated with an URI |\n| cookie | the cookie to store |\n|--------|------------------------------------------------------------------------------------------------|\n\nThrows\n\n| [NullPointerException](../../../reference/java/lang/NullPointerException.html) | if `cookie` is `null` |\n|--------------------------------------------------------------------------------|-----------------------|\n\nSee Also\n\n- [get(URI)](../../../reference/java/net/CookieStore.html#get(java.net.URI)) \n\npublic abstract [List](../../../reference/java/util/List.html)\\\u003c[HttpCookie](../../../reference/java/net/HttpCookie.html)\\\u003e\n**get**\n([URI](../../../reference/java/net/URI.html) uri) \nRetrieve cookies associated with given URI, or whose domain matches the\ngiven URI. Only cookies that have not expired are returned.\nThis is called for every outgoing HTTP request. \n\nParameters\n\n| uri | the uri associated with the cookies to be returned |\n|-----|----------------------------------------------------|\n\nReturns\n\n- an immutable list of HttpCookie, return empty list if no cookies match the given URI \n\nThrows\n\n| [NullPointerException](../../../reference/java/lang/NullPointerException.html) | if `uri` is `null` |\n|--------------------------------------------------------------------------------|--------------------|\n\nSee Also\n\n- [add(URI, HttpCookie)](../../../reference/java/net/CookieStore.html#add(java.net.URI,%20java.net.HttpCookie)) \n\npublic abstract [List](../../../reference/java/util/List.html)\\\u003c[HttpCookie](../../../reference/java/net/HttpCookie.html)\\\u003e\n**getCookies**\n() \nGet all not-expired cookies in cookie store. \n\nReturns\n\n- an immutable list of http cookies; return empty list if there's no http cookie in store \n\npublic abstract [List](../../../reference/java/util/List.html)\\\u003c[URI](../../../reference/java/net/URI.html)\\\u003e\n**getURIs**\n() \nGet all URIs which identify the cookies in this cookie store. \n\nReturns\n\n- an immutable list of URIs; return empty list if no cookie in this cookie store is associated with an URI \n\npublic abstract boolean\n**remove**\n([URI](../../../reference/java/net/URI.html) uri, [HttpCookie](../../../reference/java/net/HttpCookie.html) cookie) \nRemove a cookie from store. \n\nParameters\n\n| uri | the uri this cookie associated with. if `null`, the cookie to be removed is not associated with an URI when added; if not `null`, the cookie to be removed is associated with the given URI when added. |\n| cookie | the cookie to remove |\n|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\nReturns\n\n- `true` if this store contained the specified cookie \n\nThrows\n\n| [NullPointerException](../../../reference/java/lang/NullPointerException.html) | if `cookie` is `null` |\n|--------------------------------------------------------------------------------|-----------------------|\n\npublic abstract boolean\n**removeAll**\n() \nRemove all cookies in this cookie store. \n\nReturns\n\n- `true` if this store changed as a result of the call"]]