CookieManager Class

Definition

CookieManager provides a concrete implementation of CookieHandler, which separates the storage of cookies from the policy surrounding accepting and rejecting cookies.

[Android.Runtime.Register("java/net/CookieManager", DoNotGenerateAcw=true)]
public class CookieManager : Java.Net.CookieHandler
[<Android.Runtime.Register("java/net/CookieManager", DoNotGenerateAcw=true)>]
type CookieManager = class
    inherit CookieHandler
Inheritance
CookieManager
Attributes

Remarks

CookieManager provides a concrete implementation of CookieHandler, which separates the storage of cookies from the policy surrounding accepting and rejecting cookies. A CookieManager is initialized with a CookieStore which manages storage, and a CookiePolicy object, which makes policy decisions on cookie acceptance/rejection.

The HTTP cookie management in java.net package looks like: <blockquote>

{@code
                             use
            CookieHandler <------- HttpURLConnection
                  ^
                  | impl
                  |         use
            CookieManager -------> CookiePolicy
                        |   use
                        |--------> HttpCookie
                        |              ^
                        |              | use
                        |   use        |
                        |--------> CookieStore
                                       ^
                                       | impl
                                       |
                             Internal in-memory implementation
            }

<ul> <li> CookieHandler is at the core of cookie management. User can call CookieHandler.setDefault to set a concrete CookieHanlder implementation to be used. </li> <li> CookiePolicy.shouldAccept will be called by CookieManager.put to see whether or not one cookie should be accepted and put into cookie store. User can use any of three pre-defined CookiePolicy, namely ACCEPT_ALL, ACCEPT_NONE and ACCEPT_ORIGINAL_SERVER, or user can define his own CookiePolicy implementation and tell CookieManager to use it. </li> <li> CookieStore is the place where any accepted HTTP cookie is stored in. If not specified when created, a CookieManager instance will use an internal in-memory implementation. Or user can implements one and tell CookieManager to use it. </li> <li> Currently, only CookieStore.add(URI, HttpCookie) and CookieStore.get(URI) are used by CookieManager. Others are for completeness and might be needed by a more sophisticated CookieStore implementation, e.g. a NetscapeCookieStore. </li> </ul> </blockquote>

There're various ways user can hook up his own HTTP cookie management behavior, e.g. <blockquote> <ul> <li>Use CookieHandler.setDefault to set a brand new CookieHandler implementation <li>Let CookieManager be the default CookieHandler implementation, but implement user's own CookieStore and CookiePolicy and tell default CookieManager to use them: <blockquote>

// this should be done at the beginning of an HTTP session
                  CookieHandler.setDefault(new CookieManager(new MyCookieStore(), new MyCookiePolicy()));

</blockquote> <li>Let CookieManager be the default CookieHandler implementation, but use customized CookiePolicy: <blockquote>

// this should be done at the beginning of an HTTP session
                  CookieHandler.setDefault(new CookieManager());
                  // this can be done at any point of an HTTP session
                  ((CookieManager)CookieHandler.getDefault()).setCookiePolicy(new MyCookiePolicy());

</blockquote> </ul> </blockquote>

The implementation conforms to RFC 2965, section 3.3.

Added in 1.6.

Java documentation for java.net.CookieManager.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

CookieManager()

Create a new cookie manager.

CookieManager(ICookieStore, ICookiePolicy)

Create a new cookie manager with specified cookie store and cookie policy.

CookieManager(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
CookieStore

To retrieve current cookie store.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
Get(URI, IDictionary<String,IList<String>>)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Put(URI, IDictionary<String,IList<String>>)
SetCookiePolicy(ICookiePolicy)

To set the cookie policy of this cookie manager.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to