Cookies

Cookies are used in the HTTP environment for three use cases. The use cases include session management, which is used for logins or generally for everything that the server has to "remember". Cookies are also used for personalization and tracking.

From a technical point of view, when an HTTP server responds to the client it sends back one or more header fields named "Set-Cookie" in the response. These cookies will then be included in future requests to the HTTP server, although in this case separated by a semicolon in a single header field.

In TwinCAT the header fields described above are automatically combined with the cookies into one header field and separated by a line feed. This does not only apply to header fields of the type "Set-Cookie", but in all cases where an HTTP response of the server contains several header fields of the same name. The following sample illustrates this.

HTTP/1.1 200 OK
Content-Type: text/html
Set-Cookie: token1=Beckhoff
Set-Cookie: token2=IoT

If the response is received by the TwinCAT IoT driver, the two header fields with the name "Set-Cookie" are automatically merged into one. The following string is then output after querying the header field in the program code:

'token1=Beckhoff$Ntoken2=IoT';