The QNetworkCookieJar class implements a simple jar of QNetworkCookie 对象。 更多...
头: | #include <QNetworkCookieJar> |
qmake: | QT += network |
Since: | Qt 4.4 |
继承: | QObject |
QNetworkCookieJar (QObject * parent = nullptr) | |
virtual | ~QNetworkCookieJar () |
virtual QList<QNetworkCookie> | cookiesForUrl (const QUrl & url ) const |
virtual bool | deleteCookie (const QNetworkCookie & cookie ) |
virtual bool | insertCookie (const QNetworkCookie & cookie ) |
virtual bool | setCookiesFromUrl (const QList<QNetworkCookie> & cookieList , const QUrl & url ) |
virtual bool | updateCookie (const QNetworkCookie & cookie ) |
const QMetaObject | staticMetaObject |
QList<QNetworkCookie> | allCookies () const |
void | setAllCookies (const QList<QNetworkCookie> & cookieList ) |
virtual bool | validateCookie (const QNetworkCookie & cookie , const QUrl & url ) const |
The QNetworkCookieJar class implements a simple jar of QNetworkCookie 对象。
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.
The cookie jar is the object that holds all cookies set in previous requests. Web browsers save their cookie jars to disk in order to conserve permanent cookies across invocations of the application.
QNetworkCookieJar does not implement permanent storage: it only keeps the cookies in memory. Once the QNetworkCookieJar object is deleted, all cookies it held will be discarded as well. If you want to save the cookies, you should derive from this class and implement the saving to disk to your own storage format.
This class implements only the basic security recommended by the cookie specifications and does not implement any cookie acceptance policy (it accepts all cookies set by any requests). In order to override those rules, you should reimplement the cookiesForUrl () 和 setCookiesFromUrl () virtual functions. They are called by QNetworkReply and QNetworkAccessManager when they detect new cookies and when they require cookies.
另请参阅 QNetworkCookie , QNetworkAccessManager , QNetworkReply , QNetworkRequest ,和 QNetworkAccessManager::setCookieJar ().
创建 QNetworkCookieJar object and sets the parent object to be parent .
The cookie jar is initialized to empty.
[虚拟]
QNetworkCookieJar::
~QNetworkCookieJar
()
Destroys this cookie jar object and discards all cookies stored in it. Cookies are not saved to disk in the QNetworkCookieJar default implementation.
If you need to save the cookies to disk, you have to derive from QNetworkCookieJar and save the cookies to disk yourself.
[protected]
QList
<
QNetworkCookie
> QNetworkCookieJar::
allCookies
() const
Returns all cookies stored in this cookie jar. This function is suitable for derived classes to save cookies to disk, as well as to implement cookie expiration and other policies.
另请参阅 setAllCookies () 和 cookiesForUrl ().
[虚拟]
QList
<
QNetworkCookie
> QNetworkCookieJar::
cookiesForUrl
(const
QUrl
&
url
) const
Returns the cookies to be added to when a request is sent to url . This function is called by the default QNetworkAccessManager::createRequest (), which adds the cookies returned by this function to the request being sent.
If more than one cookie with the same name is found, but with differing paths, the one with longer path is returned before the one with shorter path. In other words, this function returns cookies sorted decreasingly by path length.
默认 QNetworkCookieJar class implements only a very basic security policy (it makes sure that the cookies' domain and path match the reply's). To enhance the security policy with your own algorithms, override cookiesForUrl().
另请参阅 setCookiesFromUrl () 和 QNetworkAccessManager::setCookieJar ().
[虚拟]
bool
QNetworkCookieJar::
deleteCookie
(const
QNetworkCookie
&
cookie
)
Deletes from cookie jar the cookie found to have the same identifier as cookie .
返回
true
若 Cookie 被删除,否则 false。
该函数在 Qt 5.0 引入。
另请参阅 QNetworkCookie::hasSameIdentifier ().
[虚拟]
bool
QNetworkCookieJar::
insertCookie
(const
QNetworkCookie
&
cookie
)
添加 cookie 到此 Cookie Jar。
返回
true
if
cookie
被添加,否则 false。
If a cookie with the same identifier already exists in the cookie jar, it will be overridden.
该函数在 Qt 5.0 引入。
[protected]
void
QNetworkCookieJar::
setAllCookies
(const
QList
<
QNetworkCookie
> &
cookieList
)
Sets the internal list of cookies held by this cookie jar to be cookieList . This function is suitable for derived classes to implement loading cookies from permanent storage, or their own cookie acceptance policies by reimplementing setCookiesFromUrl ().
另请参阅 allCookies () 和 setCookiesFromUrl ().
[虚拟]
bool
QNetworkCookieJar::
setCookiesFromUrl
(const
QList
<
QNetworkCookie
> &
cookieList
, const
QUrl
&
url
)
Adds the cookies in the list cookieList to this cookie jar. Before being inserted cookies are normalized.
返回
true
if one or more cookies are set for
url
,否则 false。
If a cookie already exists in the cookie jar, it will be overridden by those in cookieList .
默认 QNetworkCookieJar class implements only a very basic security policy (it makes sure that the cookies' domain and path match the reply's). To enhance the security policy with your own algorithms, override setCookiesFromUrl().
Also, QNetworkCookieJar does not have a maximum cookie jar size. Reimplement this function to discard older cookies to create room for new ones.
另请参阅 cookiesForUrl (), QNetworkAccessManager::setCookieJar (),和 QNetworkCookie::normalize ().
[虚拟]
bool
QNetworkCookieJar::
updateCookie
(const
QNetworkCookie
&
cookie
)
If a cookie with the same identifier as cookie exists in this cookie jar it will be updated. This function uses insertCookie ().
返回
true
if
cookie
was updated, false if no cookie in the jar matches the identifier of
cookie
.
该函数在 Qt 5.0 引入。
另请参阅 QNetworkCookie::hasSameIdentifier ().
[virtual protected]
bool
QNetworkCookieJar::
validateCookie
(const
QNetworkCookie
&
cookie
, const
QUrl
&
url
) const
返回
true
if the domain and path of
cookie
are valid, false otherwise. The
url
parameter is used to determine if the domain specified in the cookie is allowed.
该函数在 Qt 5.0 引入。