Adds, deletes, or replaces a cookie.

C Language

int web_add_cookie( const char *Cookie);

Java Language

int object.add_cookie( String Cookie );
An expression evaluating to an object of type WebApi. Usually web for Java. See also Function and Constant Prefixes.
Defines the cookie to add or modify. The Cookie parameter has the following format:
name=VALUE; (required)
domain=DOMAIN_NAME; (required)
path=PATH; (default path is "/")
The elements in the Cookie parameter are the same as the elements in the Set–Cookie HTTP Response Header. For details, see

Return Values

This function returns LR_PASS (0) on success, and LR_FAIL (1) on failure.


The following argument(s) can be parameterized using standard parameterization: Cookie

General Information

The web_add_cookie function adds a new cookie. If the name and path match an existing cookie, the existing cookie is overwritten with the new one. If the "expires" date has past, the cookie is deleted.

Although scripts handle cookies automatically, there may be cases when you need to manually control the cookies.

Note: Scripts do not use (access or modify) the cookies that are stored by your browser. Instead, each script uses the cookies that are sent to the Vuser by the server host at runtime. These cookies are maintained only temporarily while the script runs. The web–cookie functions (web_add_cookie, web_add_cookie_ex, web_remove_cookie, and web_cleanup_cookies) manipulate these temporary cookies only.

The intended use of web_add_cookie is to add cookies usually stored in the browser, prior to starting the run.

Note that in a Set–Cookie header from a server, the domain attribute is optional. If not specified, the default value of domain is the host name of the server that generated the cookie response. Since this information is not available to the load generator host when web_add_cookie is called, the domain attribute is required. To specify an empty domain, use web_add_cookie_ex..

This function is supported for all web scripts.