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
| Type | Name | Description |
|---|---|---|
string | host | The host of cookie. For example “lessons.zennolab.com”, “.zennolab.com”, etc. |
string | path | The path of cookie. |
string | name | The name of cookie. |
string | value | The value of cookie. |
DateTime | expiry | The expiry date of cookie. |
bool | isSecure | The secure flag of cookie. |
bool | isHttpOnly | The httpOnly flag of cookie. |
bool | isSession | The 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
| Type | Name | Description |
|---|---|---|
string | host | The host of cookie. For example “lessons.zennolab.com”, “.zennolab.com”, etc. |
string | path | The path of cookie. |
string | name | The name of cookie. |
string | value | The value of cookie. |
DateTime | expiry | The expiry date of cookie. |
bool | isSecure | The secure flag of cookie. |
bool | isHttpOnly | The httpOnly flag of cookie. |
bool | isSession | The session flag of cookie. |
string | sameSite | The sameSite of cookie. The sameSite may take values “Strict”, “Lax”, “None” and “Unspecified”. Default value is “Unspecified”. |
string | priority | The 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
| Type | Name | Description |
|---|---|---|
ICookieItem | item | The 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
| Type | Name | Description |
|---|---|---|
IEnumerable<ICookieItem> | items | The 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
| Type | Name | Description |
|---|---|---|
ICookieContainer | container | The 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
| Type | Name | Description |
|---|---|---|
ICookieItem | item | The 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
| Type | Name | Description |
|---|---|---|
IEnumerable<ICookieItem> | items | The 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
| Type | Name | Description |
|---|---|---|
ICookieContainer | container | The 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
| Type | Name | Description |
|---|---|---|
string | domainFilter | The 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
| Type | Name | Description |
|---|---|---|
string | host | The 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
| Type | Name | Description |
|---|---|---|
string | host | The 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
| Type | Name | Description |
|---|---|---|
string | host | The host. |
string | path | The 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
| Type | Name | Description |
|---|---|---|
string | host | The host. |
string | path | The 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
| Type | Name | Description |
|---|---|---|
string | host | The host. |
string | path | The path. |
bool | isSecure | The 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
| Type | Name | Description |
|---|---|---|
string | host | The host. |
string | path | The path. |
bool | isSecure | The 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
| Type | Name | Description |
|---|---|---|
Byte[] | cookies | The byte array representing the contents. |