Share this page

# web_add_cookie

Adds, deletes, or replaces a cookie.

## C Language

    int web_add_cookie( const char *Cookie);

Cookie Functions

## Java Language

    int object.add_cookie( String Cookie );

Cookie Functions | Java Syntax

Argument | Description
--- | ---
object | An expression evaluating to an object of type WebApi. Usually web for Java. See also Function and Constant Prefixes.
Cookie | Defines the cookie to add or modify. The Cookie parameter has the following format: name=VALUE; (required) domain=DOMAIN_NAME; (required) expires=DATE; path=PATH; (default path is "/") secure The elements in the Cookie parameter are the same as the elements in the Set–Cookie HTTP Response Header. For details, see http://wp.netscape.com/newsref/std/cookie_spec.html

## Return Values

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

## Parameterization

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.

## C Example

In the following example, the web_add_cookie function adds a cookie with the name "client_id" to the list of cookies available to the script.

web_add_cookie ("client_id=China127B; path=/; expires=Wednesday, 09–Nov–2001 23:12:40 GMT; domain=www.cnn.com");

## Java Example

In the following example, the add_cookie function adds a cookie with the name "client_id" to the list of cookies available to the script.

    web.add_cookie ("client_id=China127B; path=/; expires=Wednesday, 09-Nov-2001 23:12:40 GMT; domain=www.cnn.com"); // for Java

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: