Implementing stateful clients with cookies
- Last Updated: January 17, 2024
- 1 minute read
- OpenEdge
- Version 12.8
- Documentation
The default HTTP client is stateless (i.e. without cookies).
OpenEdge.Net.Http.StatefulHttpClient extends the standard HTTP
client and writes cookies into the IHttpRequest and reads them from
the IHttpResponse after request execution.
The OpenEdge.Net.HTTP.ICookieJar interface controls access to and
from the cookie jar. Cookies are stored in an instance of an
OpenEdge.Net.HTTP.ICookieJar class. The standard implementation
is OpenEdge.Net.HTTP.CookieJar which writes persistent cookies to
disk in JSON form.
The rules for storing cookies are:
- Cookies must be associated with a domain.
- If the cookie itself has no domain, use the request's host domain.
- If the cookie has a domain, use that. This domain may be prefixed with a wildcard '.' .
- The cookie domain and the request host domain must be the same.
- Cookies that have no expiration date are considered session cookies and are
deleted when the CookieJar is deleted/cleaned up. Session cookies can be
cleaned with the
CleanSessionCookies()method.
The rules for retrieving cookies for a request are:
- The request's host is identical to cookie's domain, or the host matches the cookie's domain.
- The request's URL path begins with the cookie path.
Examples
The following is a general example of implementing cookies in order to establish a stateful client.
Implementing cookies
|
To read/write cookies on requests and responses, use the methods from the
IHttpMessage interface as shown in the following code
sample.
Read/write methods for cookies
|
ToString()
on it (STRING(oCookie) or MESSAGE oCookie also
work. )