ICookieContainer

Assembly: ZennoLab.InterfacesLibrary
Full name: ZennoLab.InterfacesLibrary.ProjectModel.ICookieContainer
Kind: interface


Represents the container of cookies, that synchronizes with an instance.

This interface can be used in action OwnCode (C# or PHP) of ProjectMaker.

Properties

Domains

Property

IEnumerable<string> Domains { get; }

Gets collection of cookie’s domains from container.

Example

// get the path to log file
            string path = project.LogOptions.LogFile;
            // set the path to log file
            project.LogOptions.LogFile = "X:\\log.txt";
            // enable splitting for log
            project.LogOptions.SplitLogByThread = true; 
            return tmp;

Methods

Create

Method

ICookieItem Create(string host, string path, string name, string value, DateTime expiry, bool isSecure, bool isHttpOnly, bool isSession)

Creates a new cookie item.

Parameters

TypeNameDescription
stringhostThe host of cookie. For example “lessons.zennolab.com”, “.zennolab.com”, etc.
stringpathThe path of cookie.
stringnameThe name of cookie.
stringvalueThe value of cookie.
DateTimeexpiryThe expiry date of cookie.
boolisSecureThe secure flag of cookie.
boolisHttpOnlyThe httpOnly flag of cookie.
boolisSessionThe session flag of cookie.

Returns: New cookie item object.

Example

// create new cookie item
            var item = project.Profile.CookieContainer.Create(".zennolab.com", "/", "asd", "123", DateTime.Now.AddYears(1), false, false, false);
            // add item to container
            project.Profile.CookieContainer.Add(item);

Create

Method

ICookieItem Create(string host, string path, string name, string value, DateTime expiry, bool isSecure, bool isHttpOnly, bool isSession, string sameSite, string priority)

Creates a new cookie item.

Parameters

TypeNameDescription
stringhostThe host of cookie. For example “lessons.zennolab.com”, “.zennolab.com”, etc.
stringpathThe path of cookie.
stringnameThe name of cookie.
stringvalueThe value of cookie.
DateTimeexpiryThe expiry date of cookie.
boolisSecureThe secure flag of cookie.
boolisHttpOnlyThe httpOnly flag of cookie.
boolisSessionThe session flag of cookie.
stringsameSiteThe sameSite of cookie. The sameSite may take values “Strict”, “Lax”, “None” and “Unspecified”. Default value is “Unspecified”.
stringpriorityThe priority of cookie. The priority may take values “Low”, “Medium”, “High”. Default value is “Medium”.

Returns: New cookie item object.

Example

// create new cookie item
            var item = project.Profile.CookieContainer.Create(".zennolab.com", "/", "asd", "123", DateTime.Now.AddYears(1), false, false, false, "Strict", "Medium");
            // add item to container
            project.Profile.CookieContainer.Add(item);

Add

Method

void Add(ICookieItem item)

Adds the cookie item to the container.

Parameters

TypeNameDescription
ICookieItemitemThe cookie item.

Example

// create new cookie item
            var item = project.Profile.CookieContainer.Create(".zennolab.com", "/", "asd", "123", DateTime.Now.AddYears(1), false, false, false);
            // add item to container
            project.Profile.CookieContainer.Add(item);

Add

Method

void Add(IEnumerable<ICookieItem> items)

Adds the cookie items collection to the container.

Parameters

TypeNameDescription
IEnumerable<ICookieItem>itemsThe cookie items collection.

Example

// create new cookie item
            var item = project.Profile.CookieContainer.Create(".zennolab.com", "/", "asd", "123", DateTime.Now.AddYears(1), false, false, false);
            var item2 = project.Profile.CookieContainer.Create(".zennolab.com", "/", "qwe", "zxc", DateTime.Now.AddYears(1), false, false, false);
            // add item to container
            project.Profile.CookieContainer.Add(new [] { item, item2 });

Add

Method

void Add(ICookieContainer container)

Adds the contents of an another container to the container.

Parameters

TypeNameDescription
ICookieContainercontainerThe cookie container.

Example

// create new cookie container
            var container = new CookieContainer();
            // use new cookie container for http request
            ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: container);
            // add the contents of the new container to profile's container
            project.Profile.CookieContainer.Add(container);

Remove

Method

void Remove(ICookieItem item)

Removes the cookie item from the container.

Parameters

TypeNameDescription
ICookieItemitemThe cookie item.

Example

// http request with cookie container
            ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: project.Profile.CookieContainer);
            // get avaliable domains for container
            var domains = project.Profile.CookieContainer.Domains;
            if (domains.Count() > 0)
            {
                var items = project.Profile.CookieContainer.Get(domains.First());
                // remove some cookie from container
                project.Profile.CookieContainer.Remove(items.FirstOrDefault());
            }

Remove

Method

void Remove(IEnumerable<ICookieItem> items)

Removes the cookie items collection from the container.

Parameters

TypeNameDescription
IEnumerable<ICookieItem>itemsThe cookie items collection.

Example

// http request with cookie container
            ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: project.Profile.CookieContainer);
            // get avaliable domains for container
            var domains = project.Profile.CookieContainer.Domains;
            if (domains.Count() > 0)
            {
                var items = project.Profile.CookieContainer.Get(domains.First());
                // remove some cookies from container
                project.Profile.CookieContainer.Remove(items);
            }

Remove

Method

void Remove(ICookieContainer container)

Removes the contents of an another container from the container.

Parameters

TypeNameDescription
ICookieContainercontainerThe cookie container.

Example

// create new cookie container
            var container = new CookieContainer();
            // use new cookie container for http request
            ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: container);
            // remove the contents of the new container from profile's container
            project.Profile.CookieContainer.Remove(container);

Clear

Method

void Clear()

Clears the contents from the container.

Clear

Method

void Clear(string domainFilter)

Clears the contents from the container.

Parameters

TypeNameDescription
stringdomainFilterThe regular expressions for filtering by domain. If value is null or empty string, then method clears cookies for all domains. The default value is empty string.

Refresh

Method

void Refresh()

Replaces the contents of the container with cookies from the instance. Works only for project.Profile.CookieContainer.

Get

Method

IEnumerable<ICookieItem> Get(string host)

Gets a collection of cookie items corresponding to the host.

Parameters

TypeNameDescription
stringhostThe host.

Returns: The cookie items collection.

Example

// http request
            ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: project.Profile.CookieContainer);
            // get cookie items
            var items = project.Profile.CookieContainer.Get("zennolab.com");
            // output to log info of cookie item
            foreach(var item in items)
            {
                project.SendInfoToLog(item.Name + " = " + item.Value);
            }

GetPairs

Method

IEnumerable<string> GetPairs(string host)

Gets a collection of cookie strings corresponding to the host. Format is “name=value”

Parameters

TypeNameDescription
stringhostThe host.

Returns: The cookie strings collection.

Example

// http request
            ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: project.Profile.CookieContainer);
            // get cookie items
            var items = project.Profile.CookieContainer.GetPairs("zennolab.com");
            // output to log info of cookie item
            foreach(var item in items)
            {
                project.SendInfoToLog(item);
            }

Get

Method

IEnumerable<ICookieItem> Get(string host, string path)

Gets a collection of cookie items corresponding to the host and path.

Parameters

TypeNameDescription
stringhostThe host.
stringpathThe path.

Returns: The cookie items collection.

Example

// http request
            ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: project.Profile.CookieContainer);
            // get cookie items
            var items = project.Profile.CookieContainer.Get("zennolab.com", "/");
            // output to log info of cookie item
            foreach(var item in items)
            {
                project.SendInfoToLog(item.Name + " = " + item.Value);
            }

GetPairs

Method

IEnumerable<string> GetPairs(string host, string path)

Gets a collection of cookie strings corresponding to the host and path. Format is “name=value”

Parameters

TypeNameDescription
stringhostThe host.
stringpathThe path.

Returns: The cookie strings collection.

Example

// http request
            ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: project.Profile.CookieContainer);
            // get cookie items
            var items = project.Profile.CookieContainer.GetPairs("zennolab.com", "/");
            // output to log info of cookie item
            foreach(var item in items)
            {
                project.SendInfoToLog(item);
            }

Get

Method

IEnumerable<ICookieItem> Get(string host, string path, bool isSecure)

Gets a collection of cookie items corresponding to the host, path and secure flag.

Parameters

TypeNameDescription
stringhostThe host.
stringpathThe path.
boolisSecureThe secure flag. The cookie item does not correspond to the isSecure flag if isSecure = false and item.IsSecure = true, otherwise, it correspond.

Returns: The cookie items collection.

Example

// http request
            ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: project.Profile.CookieContainer);
            // get cookie items
            var items = project.Profile.CookieContainer.Get("zennolab.com", "/", false);
            // output to log info of cookie item
            foreach(var item in items)
            {
                project.SendInfoToLog(item.Name + " = " + item.Value);
            }

GetPairs

Method

IEnumerable<string> GetPairs(string host, string path, bool isSecure)

Gets a collection of cookie strings corresponding to the host, path and secure flag. Format is “name=value”

Parameters

TypeNameDescription
stringhostThe host.
stringpathThe path.
boolisSecureThe secure flag. The cookie item does not correspond to the isSecure flag if isSecure = false and item.IsSecure = true, otherwise, it correspond.

Returns: The cookie strings collection.

Example

// http request
            ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: project.Profile.CookieContainer);
            // get cookie items
            var items = project.Profile.CookieContainer.GetPairs("zennolab.com", "/", false);
            // output to log info of cookie item
            foreach(var item in items)
            {
                project.SendInfoToLog(item);
            }

Export

Method

Byte[] Export()

Exports the contents of container to the byte array.

Returns: The byte array representing the contents.

Import

Method

void Import(Byte[] cookies)

Imports the contents from the byte array.

Parameters

TypeNameDescription
Byte[]cookiesThe byte array representing the contents.