CookieContainer 类

定义

CookieCollection 对象的集合提供容器。Provides a container for a collection of CookieCollection objects.

public ref class CookieContainer
[System.Serializable]
public class CookieContainer
type CookieContainer = class
Public Class CookieContainer
继承
CookieContainer
属性

注解

CookieContainer 是一种数据结构,为 Cookie 类的实例提供存储,并以类似于数据库的方式访问。A CookieContainer is a data structure that provides storage for instances of the Cookie class, and which is accessed in a database-like manner. CookieContainer 具有一个容量限制,该限制是在创建容器或由属性更改时设置的。The CookieContainer has a capacity limit that is set when the container is created or changed by a property.

Cookie 类的实例将基于其源 URI 添加到容器中。An instance of the Cookie class is added to the container based on its originating URI. 它将添加到与 URI 关联的内部 CookieCollectionIt is added to an internal CookieCollection associated with the URI. Cookie 是从基于 URI 作为 CookieCollection的容器检索的,或者是可用于提交 HTTP WebRequests 的字符串。A Cookie is retrieved from the container based on the URI as a CookieCollection, or as a string that can be used to submit HTTP WebRequests.

CookieContainer 具有三个属性,这些属性控制容器的内容量: CapacityMaxCookieSizePerDomainCapacityThe CookieContainer has three properties that govern the volume of the content of the container: Capacity, MaxCookieSize, and PerDomainCapacity. 这些值分别为300、4096和20的默认设置。These values have the default settings of 300, 4096, and 20 respectively. Cookie 添加到容器中时,将使用这些属性来确定是否应丢弃 CookieContainer 中包含的 Cookie,以便为新项腾出空间。When a Cookie is added to the container, these properties are used to determine whether a Cookie already contained in the CookieContainer should be discarded to make room for the new one. CookieContainer 跟踪每个加法,以确保不会超出 CapacityPerDomainCapacity 限制。The CookieContainer keeps track of each addition to ensure that neither the Capacity nor the PerDomainCapacity limits are exceeded. 如果超过其中一个或两个,则删除 CookieContainer Cookie 实例。If one or both are exceeded, then Cookie instances held by the CookieContainer are removed. 首先,删除任何过期的 CookieFirst, any expired Cookie is removed. 如果必须回收更多的容量,则会清除最近使用的 CookieCollectionIf further capacity must be recaptured, then the least-recently used CookieCollection is purged.

构造函数

CookieContainer()

初始化 CookieContainer 类的新实例。Initializes a new instance of the CookieContainer class.

CookieContainer(Int32)

使用指定的表示容器可以包含的 CookieContainer 实例数的值初始化 Cookie 类的新实例。Initializes a new instance of the CookieContainer class with a specified value for the number of Cookie instances that the container can hold.

CookieContainer(Int32, Int32, Int32)

使用指定属性初始化 CookieContainer 类的新实例。Initializes a new instance of the CookieContainer class with specific properties.

字段

DefaultCookieLengthLimit

表示 Cookie 可以包含的 CookieContainer 实例的默认最大大小(以字节为单位)。Represents the default maximum size, in bytes, of the Cookie instances that the CookieContainer can hold. 此字段为常数。This field is constant.

DefaultCookieLimit

表示 Cookie 可以包含的 CookieContainer 实例的默认最大数目。Represents the default maximum number of Cookie instances that the CookieContainer can hold. 此字段为常数。This field is constant.

DefaultPerDomainCookieLimit

表示 Cookie 可以在每个域引用的 CookieContainer 实例的默认最大数目。Represents the default maximum number of Cookie instances that the CookieContainer can reference per domain. 此字段为常数。This field is constant.

属性

Capacity

获取或设置 Cookie 可以包含的 CookieContainer 实例数。Gets or sets the number of Cookie instances that a CookieContainer can hold.

Count

获取 Cookie 当前包含的 CookieContainer 实例数。Gets the number of Cookie instances that a CookieContainer currently holds.

MaxCookieSize

表示 Cookie 的最大允许长度。Represents the maximum allowed length of a Cookie.

PerDomainCapacity

获取或设置 Cookie 可以在每个域包含的 CookieContainer 实例数。Gets or sets the number of Cookie instances that a CookieContainer can hold per domain.

方法

Add(Cookie)

Cookie 添加到 CookieContainerAdds a Cookie to a CookieContainer. 此方法使用 Cookie 中的域来确定将 Cookie 与哪个域集合相关联。This method uses the domain from the Cookie to determine which domain collection to associate the Cookie with.

Add(CookieCollection)

CookieCollection 的内容添加到 CookieContainer 中。Adds the contents of a CookieCollection to the CookieContainer.

Add(Uri, Cookie)

Cookie 添加到特定 URI 的 CookieContainer 中。Adds a Cookie to the CookieContainer for a particular URI.

Add(Uri, CookieCollection)

CookieCollection 的内容添加到特定 URI 的 CookieContainer 中。Adds the contents of a CookieCollection to the CookieContainer for a particular URI.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetCookieHeader(Uri)

获取 HTTP Cookie 标头,该标头包含表示与特定 URI 关联的 Cookie 实例的 HTTP Cookie。Gets the HTTP cookie header that contains the HTTP cookies that represent the Cookie instances that are associated with a specific URI.

GetCookies(Uri)

获取包含与特定 URI 关联的 CookieCollection 实例的 CookieGets a CookieCollection that contains the Cookie instances that are associated with a specific URI.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SetCookies(Uri, String)

将 HTTP Cookie 标头中的一个或多个 Cookie 的 Cookie 实例添加到特定 URI 的 CookieContainer 中。Adds Cookie instances for one or more cookies from an HTTP cookie header to the CookieContainer for a specific URI.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅