QNetworkCookie Class

The QNetworkCookie class holds one network cookie. More...

Header: #include <QNetworkCookie>
qmake: QT += network
Since: Qt 4.4

This class was introduced in Qt 4.4.

Public Types

enum RawForm { NameAndValueOnly, Full }

Detailed Description

Cookies are small bits of information that stateless protocols like HTTP use to maintain some persistent information across requests.

A cookie is set by a remote server when it replies to a request and it expects the same cookie to be sent back when further requests are sent.

QNetworkCookie holds one such cookie as received from the network. A cookie has a name and a value, but those are opaque to the application (that is, the information stored in them has no meaning to the application). A cookie has an associated path name and domain, which indicate when the cookie should be sent again to the server.

A cookie can also have an expiration date, indicating its validity. If the expiration date is not present, the cookie is considered a "session cookie" and should be discarded when the application exits (or when its concept of session is over).

QNetworkCookie provides a way of parsing a cookie from the HTTP header format using the QNetworkCookie::parseCookies() function. However, when received in a QNetworkReply, the cookie is already parsed.

This class implements cookies as described by the initial cookie specification by Netscape, which is somewhat similar to the RFC 2109 specification, plus the "HttpOnly" extension. The more recent RFC 2965 specification (which uses the Set-Cookie2 header) is not supported.

See also QNetworkCookieJar, QNetworkRequest, and QNetworkReply.

Member Type Documentation

enum QNetworkCookie::RawForm

This enum is used with the toRawForm() function to declare which form of a cookie shall be returned.

ConstantValueDescription
QNetworkCookie::NameAndValueOnly0makes toRawForm() return only the "NAME=VALUE" part of the cookie, as suitable for sending back to a server in a client request's "Cookie:" header. Multiple cookies are separated by a semi-colon in the "Cookie:" header field.
QNetworkCookie::Full1makes toRawForm() return the full cookie contents, as suitable for sending to a client in a server's "Set-Cookie:" header.

Note that only the Full form of the cookie can be parsed back into its original contents.

See also toRawForm() and parseCookies().