Skip to content
QiTASC.com / intaQt Built-ins / HTTP Built-ins /
HTTP Cookie and Cookie Store
/ .. / .. /
HTTP Cookie and Cookie Store





HTTP Built-ins - Cookie and Cookie Store

These HTTP Built-ins create new cookies and cookie stores. New cookie and cookie store functions should always have an associated HTTP request and response called.

Creates a new cookie by specifying its name and value.

Syntax

1
<result Cookie> := Http.newCookie(<name String>, <value String>)

Returns
The cookie.

Parameters

  • name (Optional) - The cookie's name

  • value (Optional) - The cookie's value

Example

1
2
3
4
5
stepdef "create cookie"
    mycookie := Http.newCookie("YourName", "YourAge")
    mycookie.setDomain("www.anywebpage.com")
    mycookie.setPath("/yourTools/yourPath/")
end

Available Builder Methods

The following methods can be used with the newCookie function. They must be prepended by the cookie object. For example, mycookie.setDomain("www.google.com").

Set Comment and Get Comment

Sets a comment that describes the cookie.

Syntax

1
<cookie Cookie>.setComment(<comment String>)

Parameters

  • cookie - The cookie

  • comment - The comment's content

Example

1
cookie.setComment("###################### Cookie Comment: example cookie")

Get Comment

Returns a cookies comment that has been created by setComment.

Syntax

1
<comment String> := <cookie Cookie>.getComment()

Returns
The cookie's comment.

Parameters

  • cookie - The cookie

  • comment - The comment's content

Example

1
2
3
4
cookie := Http.newCookie("Age", "Name")
cookie.setComment("###################### Cookie Comment: example cookie")
test := cookie.getComment()
println(test)

Set Domain

Specifies the domain where the cookies should be visible.

Syntax

1
<cookie Cookie>.setDomain(<domain String>)

Parameters

  • cookie - The cookie

  • domain - The domain's URL

Example

1
2
3
cookie.setDomain("www.anywebpage.com")
test := cookie.getDomain()
println(test)

Get Domain

Returns the cookie's domain.

Syntax

1
<domain String> := <cookie Cookie>.getDomain()

Returns
The cookie's domain name.

Parameters

  • cookie - The cookie

Set Path

Set the path for where the cookies are valid.

Syntax

1
<cookie Cookie>.setPath(<uri String>)

Parameters

  • cookie - The cookie

  • uri - The path where the cookies are valid

Example

1
cookie.setPath("/yourTools/yourPath/")

Get Path

Returns the valid cookies' path.

Syntax

1
<uri String> := <cookie Cookie>.getPath()

Returns
The path where the cookies are valid.

Parameter

  • cookie - The cookie

Example

1
2
3
cookie.setPath("/yourTools/yourPath/")
test := cookie.getPath()
println(test)

Set Value

Sets a new value for the cookie.

Syntax

1
<cookie Cookie>.setValue(<newValue String>)

Parameters

  • cookie - The cookie

  • newValue - The cookie's new value

Example

1
cookie.setValue("############# value")

Get Value

Returns the cookie's value.

Syntax

1
<newValue String> := <cookie Cookie>.getValue()

Returns
The cookie's new value.

Parameters

  • cookie - The cookie

Example

1
2
3
cookie.setValue("############# value")
test := cookie.getValue()
println(test)

Set Secure

States whether the cookie should be sent using a secure protocol or not.

Syntax

1
<cookie Cookie>.setSecure(<isSecure Boolean>)

Parameters

  • cookie - The cookie

  • isSecure -

    • true if the cookie should be sent using a secure protocol
    • false otherwise
    • Default is set to false

Example

1
cookie.setSecure(false)

Clone

Returns a copy of the cookie.

Syntax

1
<cookie Cookie>.clone()

Parameter

  • cookie - The cookie

Example

1
mycookie.clone()

The newCookieStore() function returns a new cookie store. Additional builder methods can be used to add, return or clear cookies.

Syntax

1
<result CookieStore> := Http.newCookieStore()

Returns
The new cookie store.

Example

1
cookieStore := Http.newCookieStore()

The following methods can be used with the newCookieStore() function. They must be prepended by the cookie store object. For example, cookieStore.addCookie(cookie).

This method adds a cookie, and replaces any existing cookies of that same type.

Syntax

1
<cookieStore CookieStore>.addCookie(<cookie Cookie>)

Parameters

  • CookieStore - The cookie store

  • cookie - The cookie to be added to the cookie store

Example

1
cookieStore.addCookie(cookie)

Clear Cookies

This method clears all cookies.

Syntax

1
<cookieStore CookieStore>.clear()

Parameter

  • cookieStore - The cookie store

Example

1
mycookiestore.clear()

Get Cookies

This method returns a list of cookies contained in the cookie store. It can be used with any non-static RequestBuilder method as described in the Apache documentation.

Syntax

1
<cookies List<Cookie>> := <cookieStore CookieStore>.getCookies()

Returns
A list of cookies.

Parameter * cookieStore - The cookie store

Example

1
cookies := mycookiestore.getCookies()

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
stepdef "cookie test"
    client := Http.newClient()
    cookieStore := Http.newCookieStore()
    cookie := Http.newCookie("YourName", "YourAge")
    cookie.setDomain("www.anywebpage.com")
    cookie.setPath("/yourTools/yourPath/")
    cookieStore.addCookie(cookie)

    clientContext := Http.newHttpClientContext()
    clientContext.setCookieStore(cookieStore)
    request := Http
        .get("http://www.anywebpage.com/yourTools/yourPath/")
        .build()
    response := client.execute(request, clientContext )
    responseBody := Http.getContentString(response)
    println(responseBody)
end