Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Tous les espaces de nom  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QNetworkRequest Class Reference
[QtNetwork module]

The QNetworkRequest class holds one request to be sent with the Network Access API. More...

 #include <QNetworkRequest>

This class was introduced in Qt 4.4.

Public Types

  • enum Attribute { HttpStatusCodeAttribute, HttpReasonPhraseAttribute, RedirectionTargetAttribute, ConnectionEncryptedAttribute, ..., UserMax }
  • enum CacheLoadControl { AlwaysNetwork, PreferNetwork, PreferCache, AlwaysCache }
  • enum KnownHeaders { ContentTypeHeader, ContentLengthHeader, LocationHeader, LastModifiedHeader, CookieHeader, SetCookieHeader }

Public Functions


Detailed Description

The QNetworkRequest class holds one request to be sent with the Network Access API.

QNetworkRequest is part of the Network Access API and is the class holding the information necessary to send a request over the network. It contains a URL and some ancillary information that can be used to modify the request.

See also QNetworkReply and QNetworkAccessManager.


Member Type Documentation

enum QNetworkRequest::Attribute

Attribute codes for the QNetworkRequest and QNetworkReply.

Attributes are extra meta-data that are used to control the behavior of the request and to pass further information from the reply back to the application. Attributes are also extensible, allowing custom implementations to pass custom values.

The following table explains what the default attribute codes are, the QVariant types associated, the default value if said attribute is missing and whether it's used in requests or replies.

ConstantValueDescription
QNetworkRequest::HttpStatusCodeAttribute0Replies only, type: QVariant::Int (no default) Indicates the HTTP status code received from the HTTP server (like 200, 304, 404, 401, etc.). If the connection was not HTTP-based, this attribute will not be present.
QNetworkRequest::HttpReasonPhraseAttribute1Replies only, type: QVariant::ByteArray (no default) Indicates the HTTP reason phrase as received from the HTTP server (like "Ok", "Found", "Not Found", "Access Denied", etc.) This is the human-readable representation of the status code (see above). If the connection was not HTTP-based, this attribute will not be present.
QNetworkRequest::RedirectionTargetAttribute2Replies only, type: QVariant::Url (no default) If present, it indicates that the server is redirecting the request to a different URL. The Network Access API does not by default follow redirections: it's up to the application to determine if the requested redirection should be allowed, according to its security policies.
QNetworkRequest::ConnectionEncryptedAttribute3Replies only, type: QVariant::Bool (default: false) Indicates whether the data was obtained through an encrypted (secure) connection.
QNetworkRequest::CacheLoadControlAttribute4Requests only, type: QVariant::Int (default: QNetworkRequest::PreferNetwork) Controls how the cache should be accessed. The possible values are those of QNetworkRequest::CacheLoadControl. Note that the default QNetworkAccessManager implementation does not support caching. However, this attribute may be used by certain backends to modify their requests (for example, for caching proxies).
QNetworkRequest::CacheSaveControlAttribute5Requests only, type: QVariant::Bool (default: true) Controls if the data obtained should be saved to cache for future uses. If the value is false, the data obtained will not be automatically cached. If true, data may be cached, provided it is cacheable (what is cacheable depends on the protocol being used). Note that the default QNetworkAccessManager implementation does not support caching, so it will ignore this attribute.
QNetworkRequest::User1000Special type. Additional information can be passed in QVariants with types ranging from User to UserMax. The default implementation of Network Access will ignore any request attributes in this range and it will not produce any attributes in this range in replies. The range is reserved for extensions of QNetworkAccessManager.
QNetworkRequest::UserMax32767Special type. See User.

enum QNetworkRequest::CacheLoadControl

Controls the caching mechanism of QNetworkAccessManager.

ConstantValueDescription
QNetworkRequest::AlwaysNetwork0always load from network and do not check if the cache has a valid entry (similar to the "Reload" feature in browsers)
QNetworkRequest::PreferNetwork1default value; load from the network if the cached entry is older than the network entry
QNetworkRequest::PreferCache2load from cache if available, otherwise load from network. Note that this can return possibly stale (but not expired) items from cache.
QNetworkRequest::AlwaysCache3only load from cache, indicating error if the item was not cached (i.e., off-line mode)

enum QNetworkRequest::KnownHeaders

List of known header types that QNetworkRequest parses. Each known header is also represented in raw form with its full HTTP name.

ConstantValueDescription
QNetworkRequest::ContentTypeHeader0corresponds to the HTTP Content-Type header and contains a string containing the media (MIME) type and any auxiliary data (for instance, charset)
QNetworkRequest::ContentLengthHeader1corresponds to the HTTP Content-Length header and contains the length in bytes of the data transmitted.
QNetworkRequest::LocationHeader2corresponds to the HTTP Location header and contains a URL representing the actual location of the data, including the destination URL in case of redirections.
QNetworkRequest::LastModifiedHeader3corresponds to the HTTP Last-Modified header and contains a QDateTime representing the last modification date of the contents
QNetworkRequest::CookieHeader4corresponds to the HTTP Cookie header and contains a QList<QNetworkCookie> representing the cookies to be sent back to the server
QNetworkRequest::SetCookieHeader5corresponds to the HTTP Set-Cookie header and contains a QList<QNetworkCookie> representing the cookies sent by the server to be stored locally

See also header(), setHeader(), rawHeader(), and setRawHeader().


Member Function Documentation

QNetworkRequest::QNetworkRequest ( const QUrl & url = QUrl() )

Constructs a QNetworkRequest object with url as the URL to be requested.

See also url() and setUrl().

QNetworkRequest::QNetworkRequest ( const QNetworkRequest & other )

Creates a copy of other.

QNetworkRequest::~QNetworkRequest ()

Disposes of the QNetworkRequest object.

QVariant QNetworkRequest::attribute ( Attribute code, const QVariant & defaultValue = QVariant() ) const

Returns the attribute associated with the code code. If the attribute has not been set, it returns defaultValue.

Note: this function does not apply the defaults listed in QNetworkRequest::Attribute.

See also setAttribute() and QNetworkRequest::Attribute.

bool QNetworkRequest::hasRawHeader ( const QByteArray & headerName ) const

Returns true if the raw header headerName is present in this network request.

See also rawHeader() and setRawHeader().

QVariant QNetworkRequest::header ( KnownHeaders header ) const

Returns the value of the known network header header if it is present in this request. If it is not present, returns QVariant() (i.e., an invalid variant).

See also KnownHeaders, rawHeader(), and setHeader().

QByteArray QNetworkRequest::rawHeader ( const QByteArray & headerName ) const

Returns the raw form of header headerName. If no such header is present, an empty QByteArray is returned, which may be indistinguishable from a header that is present but has no content (use hasRawHeader() to find out if the header exists or not).

Raw headers can be set with setRawHeader() or with setHeader().

See also header() and setRawHeader().

QList<QByteArray> QNetworkRequest::rawHeaderList () const

Returns a list of all raw headers that are set in this network request. The list is in the order that the headers were set.

See also hasRawHeader() and rawHeader().

void QNetworkRequest::setAttribute ( Attribute code, const QVariant & value )

Sets the attribute associated with code code to be value value. If the attribute is already set, the previous value is discarded. In special, if value is an invalid QVariant, the attribute is unset.

See also attribute() and QNetworkRequest::Attribute.

void QNetworkRequest::setHeader ( KnownHeaders header, const QVariant & value )

Sets the value of the known header header to be value, overriding any previously set headers. This operation also sets the equivalent raw HTTP header.

See also KnownHeaders, setRawHeader(), and header().

void QNetworkRequest::setRawHeader ( const QByteArray & headerName, const QByteArray & headerValue )

Sets the header headerName to be of value headerValue. If headerName corresponds to a known header (see QNetworkRequest::KnownHeaders), the raw format will be parsed and the corresponding "cooked" header will be set as well.

For example:

 request.setRawHeader("Last-Modified", "Sun, 06 Nov 1994 08:49:37 GMT");

will also set the known header LastModifiedHeader to be the QDateTime object of the parsed date.

Note: setting the same header twice overrides the previous setting. To accomplish the behaviour of multiple HTTP headers of the same name, you should concatenate the two values, separating them with a comma (",") and set one single raw header.

See also KnownHeaders, setHeader(), hasRawHeader(), and rawHeader().

void QNetworkRequest::setSslConfiguration ( const QSslConfiguration & config )

Sets this network request's SSL configuration to be config. The settings that apply are the private key, the local certificate, the SSL protocol (SSLv2, SSLv3, TLSv1 where applicable) and the ciphers that the SSL backend is allowed to use.

By default, no SSL configuration is set, which allows the backends to choose freely what configuration is best for them.

See also sslConfiguration() and QSslConfiguration::defaultConfiguration().

void QNetworkRequest::setUrl ( const QUrl & url )

Sets the URL this network request is referring to to be url.

See also url().

QSslConfiguration QNetworkRequest::sslConfiguration () const

Returns this network request's SSL configuration. By default, no SSL settings are specified.

See also setSslConfiguration().

QUrl QNetworkRequest::url () const

Returns the URL this network request is referring to.

See also setUrl().

bool QNetworkRequest::operator!= ( const QNetworkRequest & other ) const

Returns false if this object is not the same as other.

See also operator==().

QNetworkRequest & QNetworkRequest::operator= ( const QNetworkRequest & other )

Creates a copy of other

bool QNetworkRequest::operator== ( const QNetworkRequest & other ) const

Returns true if this object is the same as other (i.e., if they have the same URL, same headers and same meta-data settings).

See also operator!=().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 59
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Labs au hasard

Logo

Construire l'avenir : (ré-)introduction aux composants de Qt Quick

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.4
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web