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
USING OpenEdge.Net.HTTP.IHttpClient.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Net.HTTP.ICookieJar.
USING OpenEdge.Net.HTTP.CookieJarBuilder.
USING OpenEdge.Net.HTTP.Cookie.
DEFINE VARIABLE moHttpClient AS IHttpClient NO-UNDO.