Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QNetworkCookieJar Class

TheQNetworkCookieJar class implements a simple jar ofQNetworkCookie objectsMore...

Header:#include <QNetworkCookieJar>
Since: Qt 4.4
Inherits:QObject

Public Functions

QNetworkCookieJar(QObject * parent = 0)
virtual~QNetworkCookieJar()
virtual QList<QNetworkCookie>cookiesForUrl(const QUrl & url) const
virtual boolsetCookiesFromUrl(const QList<QNetworkCookie> & cookieList, const QUrl & url)
  • 29 public functions inherited fromQObject

Protected Functions

QList<QNetworkCookie>allCookies() const
voidsetAllCookies(const QList<QNetworkCookie> & cookieList)
  • 8 protected functions inherited fromQObject

Additional Inherited Members

  • 1 property inherited fromQObject
  • 1 public slot inherited fromQObject
  • 1 signal inherited fromQObject
  • 7 static public members inherited fromQObject

Detailed Description

TheQNetworkCookieJar class implements a simple jar ofQNetworkCookie objects

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 theQNetworkCookieJar 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 thecookiesForUrl() andsetCookiesFromUrl() virtual functions. They are called byQNetworkReply andQNetworkAccessManager when they detect new cookies and when they require cookies.

See alsoQNetworkCookie,QNetworkAccessManager,QNetworkReply,QNetworkRequest, andQNetworkAccessManager::setCookieJar().

Member Function Documentation

QNetworkCookieJar::QNetworkCookieJar(QObject * parent = 0)

Creates aQNetworkCookieJar object and sets the parent object to beparent.

The cookie jar is initialized to empty.

[virtual]QNetworkCookieJar::~QNetworkCookieJar()

Destroys this cookie jar object and discards all cookies stored in it. Cookies are not saved to disk in theQNetworkCookieJar default implementation.

If you need to save the cookies to disk, you have to derive fromQNetworkCookieJar 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.

See alsosetAllCookies() andcookiesForUrl().

[virtual]QList<QNetworkCookie> QNetworkCookieJar::cookiesForUrl(constQUrl & url) const

Returns the cookies to be added to when a request is sent tourl. This function is called by the defaultQNetworkAccessManager::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.

The defaultQNetworkCookieJar 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().

See alsosetCookiesFromUrl() andQNetworkAccessManager::setCookieJar().

[protected]void QNetworkCookieJar::setAllCookies(constQList<QNetworkCookie> & cookieList)

Sets the internal list of cookies held by this cookie jar to becookieList. This function is suitable for derived classes to implement loading cookies from permanent storage, or their own cookie acceptance policies by reimplementingsetCookiesFromUrl().

See alsoallCookies() andsetCookiesFromUrl().

[virtual]bool QNetworkCookieJar::setCookiesFromUrl(constQList<QNetworkCookie> & cookieList, constQUrl & url)

Adds the cookies in the listcookieList to this cookie jar. Default values for path and domain are taken from theurl object.

Returns true if one or more cookies are set forurl, otherwise false.

If a cookie already exists in the cookie jar, it will be overridden by those incookieList.

The defaultQNetworkCookieJar 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.

See alsocookiesForUrl() andQNetworkAccessManager::setCookieJar().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp