The QNetworkCookie class holds one network cookie. More..

QNetworkCookie类保存一个网络cookie。

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

List of all members, including inherited members

所有成员的列表,包括继承的成员
Public Types

enum RawForm { NameAndValueOnly, Full }
Public Functions

QNetworkCookie(const QByteArray & name = QByteArray(), const QByteArray & value = QByteArray())
QNetworkCookie(const QNetworkCookie & other)
~QNetworkCookie()
QString domain() const
QDateTime expirationDate() const
bool hasSameIdentifier(const QNetworkCookie & other) const
bool isHttpOnly() const
bool isSecure() const
bool isSessionCookie() const
QByteArray name() const
void normalize(const QUrl & url)
QString path() const
void setDomain(const QString & domain)
void setExpirationDate(const QDateTime & date)
void setHttpOnly(bool enable)
void setName(const QByteArray & cookieName)
void setPath(const QString & path)
void setSecure(bool enable)
void setValue(const QByteArray & value)
void swap(QNetworkCookie & other)
QByteArray toRawForm(RawForm form = Full) const
QByteArray value() const
bool operator!=(const QNetworkCookie & other) const
QNetworkCookie & operator=(const QNetworkCookie & other)
bool operator==(const QNetworkCookie & other) const

Static Public Members 静态公共成员

QList<QNetworkCookie> parseCookies(const QByteArray & cookieString)
Detailed Description详细说明

The QNetworkCookie class holds one network cookie.

QNetworkCookie类保存一个网络cookie。

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

cookie是无状态协议(如HTTP)用来在请求之间维护一些持久信息的小块信息。

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.

cookie由远程服务器在响应请求时设置,它希望在发送进一步的请求时返回相同的cookie。

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.

QNetworkCookie保存从网络接收的此类cookie。cookie有一个名称和一个值,但对应用程序是不透明的(也就是说,存储在其中的信息对应用程序没有意义)。cookie有一个关联的路径名和域,它们指示何时将cookie再次发送到服务器。

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).

cookie也可以有一个有效期,表示其有效性。如果过期日期不存在,则cookie将被视为“会话cookie”,并应在应用程序退出时(或其会话概念结束时)丢弃。

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.

QNetworkCookie提供了一种使用QNetworkCookie::parseCookies()函数从HTTP头格式解析cookie的方法。但是,当在QNetworkReply中接收到cookie时,cookie已经被解析了。

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.

这个类实现Netscape的初始cookie规范所描述的cookie,这个规范有点类似于rfc2109规范,加上“HttpOnly”扩展。不支持较新的RFC2965规范(它使用Set-Cookie2头)。

See also QNetworkCookieJar, QNetworkRequest, and QNetworkReply.

另请参见qnetworkcokiejar、QNetworkRequest和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.

此枚举与toRawForm()函数一起使用,以声明应返回哪种形式的cookie。

Constant Value Description
QNetworkCookie::NameAndValueOnly 0 makes 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::Full 1 makes 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.

定值说明

QNetworkCookie::NameAndValueOnly 0使toRawForm()只返回cookie的“NAME=VALUE”部分,适合于在客户端请求的“cookie:”头中发送回服务器。多个Cookie在“Cookie:”头字段中用分号分隔。

QNetworkCookie::Full 1使toRawForm()返回完整的cookie内容,适合于发送到服务器的“setcookie:”头中的客户机。

请注意,只有完整形式的cookie才能解析回其原始内容。

See also toRawForm() and parseCookies().

Member Function Documentation

QNetworkCookie::QNetworkCookie(const QByteArray & name = QByteArray(), const QByteArray & value = QByteArray())
Create a new QNetworkCookie object, initializing the cookie name to name and its value to value.

创建一个新的QNetworkCookie对象,将cookie名称初始化为name,将其值初始化为value。

A cookie is only valid if it has a name. However, the value is opaque to the application and being empty may have significance to the remote server.

cookie只有在有名称时才有效。但是,该值对应用程序是不透明的,并且为空可能对远程服务器有意义。

QNetworkCookie::QNetworkCookie(const QNetworkCookie & other)
Creates a new QNetworkCookie object by copying the contents of other.

QNetworkCookie::~QNetworkCookie()
Destroys this QNetworkCookie object.

QString QNetworkCookie::domain() const
Returns the domain this cookie is associated with. This corresponds to the "domain" field of the cookie string.

返回与此cookie关联的域。这对应于cookie字符串的“domain”字段。

Note that the domain here may start with a dot, which is not a valid hostname. However, it means this cookie matches all hostnames ending with that domain name.

请注意,这里的域可能以点开头,这不是有效的主机名。但是,这意味着这个cookie匹配所有以该域名结尾的主机名。

See also setDomain().

QDateTime QNetworkCookie::expirationDate() const
Returns the expiration date for this cookie. If this cookie is a session cookie, the QDateTime returned will not be valid. If the date is in the past, this cookie has already expired and should not be sent again back to a remote server.

返回此cookie的过期日期。如果此cookie是会话cookie,则返回的QDateTime将无效。如果日期已过,则此cookie已过期,不应再次发送回远程服务器。

The expiration date corresponds to the parameters of the "expires" entry in the cookie string.到期日期对应于cookie字符串中“expires”项的参数。

See also isSessionCookie() and setExpirationDate().

bool QNetworkCookie::hasSameIdentifier(const QNetworkCookie & other) const
Returns true if this cookie has the same identifier tuple as other. The identifier tuple is composed of the name, domain and path.

如果此cookie与其他cookie具有相同的标识符元组,则返回true。标识符元组由名称、域和路径组成。

See also operator==().

bool QNetworkCookie::isHttpOnly() const
Returns true if the "HttpOnly" flag is enabled for this cookie.

如果为此cookie启用了“HttpOnly”标志,则返回true。

A cookie that is "HttpOnly" is only set and retrieved by the network requests and replies; i.e., the HTTP protocol. It is not accessible from scripts running on browsers.

“HttpOnly”的cookie仅由网络请求和应答(即HTTP协议)设置和检索。无法从浏览器上运行的脚本访问它。

This function was introduced in Qt 4.5.

See also isSecure().

bool QNetworkCookie::isSecure() const
Returns true if the "secure" option was specified in the cookie string, false otherwise.

如果在cookie字符串中指定了“secure”选项,则返回true,否则返回false。

Secure cookies may contain private information and should not be resent over unencrypted connections.

安全Cookie可能包含私人信息,不应通过未加密的连接重新发送。

See also setSecure().

bool QNetworkCookie::isSessionCookie() const
Returns true if this cookie is a session cookie. A session cookie is a cookie which has no expiration date, which means it should be discarded when the application's concept of session is over (usually, when the application exits).

如果此cookie是会话cookie,则返回true。会话cookie是没有过期日期的cookie,这意味着当应用程序的会话概念结束时(通常,当应用程序退出时),应该丢弃它。

See also expirationDate() and setExpirationDate().

QByteArray QNetworkCookie::name() const
Returns the name of this cookie. The only mandatory field of a cookie is its name, without which it is not considered valid.

返回此cookie的名称。cookie的唯一必需字段是其名称,没有该字段将被视为无效。

See also setName() and value().

void QNetworkCookie::normalize(const QUrl & url)
This functions normalizes the path and domain of the cookie if they were previously empty. The url parameter is used to determine the correct domain and path.

如果cookie的路径和域以前是空的,那么这个函数将规范化它们。url参数用于确定正确的域和路径。

This function was introduced in Qt 5.0.这个函数是在qt5.0中引入的。

QList<QNetworkCookie> QNetworkCookie::parseCookies(const QByteArray & cookieString) [static]
Parses the cookie string cookieString as received from a server response in the "Set-Cookie:" header. If there's a parsing error, this function returns an empty list.

从“Set cookie:”头中的服务器响应接收到的cookie字符串cookieString。如果存在解析错误,此函数将返回一个空列表。

Since the HTTP header can set more than one cookie at the same time, this function returns a QList<QNetworkCookie>, one for each cookie that is parsed.

由于HTTP头可以同时设置多个cookie,因此此函数返回一个QList<QNetworkCookie>,每个解析的cookie都有一个。

See also toRawForm().

QString QNetworkCookie::path() const
Returns the path associated with this cookie. This corresponds to the "path" field of the cookie string.

返回与此cookie关联的路径。这对应于cookie字符串的“path”字段。

See also setPath().

void QNetworkCookie::setDomain(const QString & domain)
Sets the domain associated with this cookie to be domain.

将与此cookie关联的域设置为域。

See also domain().

void QNetworkCookie::setExpirationDate(const QDateTime & date)
Sets the expiration date of this cookie to date. Setting an invalid expiration date to this cookie will mean it's a session cookie.

将此cookie的过期日期设置为date。为此cookie设置无效的过期日期将意味着它是会话cookie。

See also isSessionCookie() and expirationDate().

void QNetworkCookie::setHttpOnly(bool enable)
Sets this cookie's "HttpOnly" flag to enable.

This function was introduced in Qt 4.5.

See also isHttpOnly().

void QNetworkCookie::setName(const QByteArray & cookieName)
Sets the name of this cookie to be cookieName. Note that setting a cookie name to an empty QByteArray will make this cookie invalid.

将此cookie的名称设置为cookieName。请注意,将cookie名称设置为空的QByteArray将使此cookie无效。

See also name() and value().

void QNetworkCookie::setPath(const QString & path)
Sets the path associated with this cookie to be path.

将与此cookie关联的路径设置为path。

See also path().

void QNetworkCookie::setSecure(bool enable)
Sets the secure flag of this cookie to enable.

设置要启用的此cookie的安全标志。

Secure cookies may contain private information and should not be resent over unencrypted connections.

安全Cookie可能包含私人信息,不应通过未加密的连接重新发送。

See also isSecure().

void QNetworkCookie::setValue(const QByteArray & value)
Sets the value of this cookie to be value.

将此cookie的值设置为value。

See also value() and name().

void QNetworkCookie::swap(QNetworkCookie & other)
Swaps this cookie with other. This function is very fast and never fails.

把这个曲奇换成另一个。这个功能非常快,从不失败。

This function was introduced in Qt 5.0.

QByteArray QNetworkCookie::toRawForm(RawForm form = Full) const
Returns the raw form of this QNetworkCookie. The QByteArray returned by this function is suitable for an HTTP header, either in a server response (the Set-Cookie header) or the client request (the Cookie header). You can choose from one of two formats, using form.

返回此QNetworkCookie的原始形式。此函数返回的QByteArray适用于HTTP头,无论是在服务器响应(Set Cookie头)还是在客户机请求(Cookie头)中。您可以使用form从两种格式中选择一种。

See also parseCookies().

QByteArray QNetworkCookie::value() const
Returns this cookies value, as specified in the cookie string. Note that a cookie is still valid if its value is empty.

返回cookie字符串中指定的cookie值。请注意,如果cookie的值为空,则它仍然有效

Cookie name-value pairs are considered opaque to the application: that is, their values don't mean anything.

Cookie名称-值对对于应用程序来说是不透明的:也就是说,它们的值没有任何意义。

See also setValue() and name().

bool QNetworkCookie::operator!=(const QNetworkCookie & other) const
Returns true if this cookie is not equal to other.

如果此cookie不等于其他cookie,则返回true。

See also operator==().

QNetworkCookie & QNetworkCookie::operator=(const QNetworkCookie & other)
Copies the contents of the QNetworkCookie object other to this object.

将QNetworkCookie对象的内容复制到此对象。

bool QNetworkCookie::operator==(const QNetworkCookie & other) const
Returns true if this cookie is equal to other. This function only returns true if all fields of the cookie are the same.

如果此cookie等于其他cookie,则返回true。只有当cookie的所有字段都相同时,此函数才返回true。

However, in some contexts, two cookies of the same name could be considered equal.

但是,在某些情况下,两个同名的cookie可以被认为是相等的。

This function was introduced in Qt 5.0.

See also operator!=() and hasSameIdentifier().

 

posted on 2020-09-27 15:33  七星落地  阅读(359)  评论(0编辑  收藏  举报