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

QNetworkRequest Class

TheQNetworkRequest class holds a request to be sent withQNetworkAccessManager.More...

Header:#include <QNetworkRequest>
Since: Qt 4.4

Public Types

enumAttribute { HttpStatusCodeAttribute, HttpReasonPhraseAttribute, RedirectionTargetAttribute, ConnectionEncryptedAttribute, ..., UserMax }
enumCacheLoadControl { AlwaysNetwork, PreferNetwork, PreferCache, AlwaysCache }
enumKnownHeaders { ContentTypeHeader, ContentLengthHeader, LocationHeader, LastModifiedHeader, CookieHeader, SetCookieHeader }
enumLoadControl { Automatic, Manual }
enumPriority { HighPriority, NormalPriority, LowPriority }

Public Functions

QNetworkRequest(const QUrl & url = QUrl())
QNetworkRequest(const QNetworkRequest & other)
~QNetworkRequest()
QVariantattribute(Attribute code, const QVariant & defaultValue = QVariant()) const
boolhasRawHeader(const QByteArray & headerName) const
QVariantheader(KnownHeaders header) const
QObject *originatingObject() const
Prioritypriority() const
QByteArrayrawHeader(const QByteArray & headerName) const
QList<QByteArray>rawHeaderList() const
voidsetAttribute(Attribute code, const QVariant & value)
voidsetHeader(KnownHeaders header, const QVariant & value)
voidsetOriginatingObject(QObject * object)
voidsetPriority(Priority priority)
voidsetRawHeader(const QByteArray & headerName, const QByteArray & headerValue)
voidsetSslConfiguration(const QSslConfiguration & config)
voidsetUrl(const QUrl & url)
QSslConfigurationsslConfiguration() const
QUrlurl() const
booloperator!=(const QNetworkRequest & other) const
QNetworkRequest &operator=(const QNetworkRequest & other)
booloperator==(const QNetworkRequest & other) const

Detailed Description

TheQNetworkRequest class holds a request to be sent withQNetworkAccessManager.

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 alsoQNetworkReply andQNetworkAccessManager.

Member Type Documentation

enum QNetworkRequest::Attribute

Attribute codes for theQNetworkRequest andQNetworkReply.

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, theQVariant 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. The returned URL might be relative. UseQUrl::resolved() to create an absolute URL out of it.
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 ofQNetworkRequest::CacheLoadControl. Note that the defaultQNetworkAccessManager 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).
QNetworkRequest::SourceIsFromCacheAttribute6Replies only, type:QVariant::Bool (default: false) Indicates whether the data was obtained from cache or not.
QNetworkRequest::DoNotBufferUploadDataAttribute7Requests only, type:QVariant::Bool (default: false) Indicates whether theQNetworkAccessManager code is allowed to buffer the upload data, e.g. when doing a HTTP POST. When using this flag with sequential upload data, theContentLengthHeader header must be set.
QNetworkRequest::HttpPipeliningAllowedAttribute8Requests only, type:QVariant::Bool (default: false) Indicates whether theQNetworkAccessManager code is allowed to use HTTP pipelining with this request.
QNetworkRequest::HttpPipeliningWasUsedAttribute9Replies only, type:QVariant::Bool Indicates whether the HTTP pipelining was used for receiving this reply.
QNetworkRequest::CustomVerbAttribute10Requests only, type:QVariant::ByteArray Holds the value for the custom HTTP verb to send (destined for usage of other verbs than GET, POST, PUT and DELETE). This verb is set when callingQNetworkAccessManager::sendCustomRequest().
QNetworkRequest::CookieLoadControlAttribute11Requests only, type:QVariant::Int (default:QNetworkRequest::Automatic) Indicates whether to send 'Cookie' headers in the request. This attribute is set to false byQtWebKit when creating a cross-originXMLHttpRequest where withCredentials has not been set explicitly to true by the Javascript that created the request. Seehere for more information. (This value was introduced in 4.7.)
QNetworkRequest::CookieSaveControlAttribute13Requests only, type:QVariant::Int (default:QNetworkRequest::Automatic) Indicates whether to save 'Cookie' headers received from the server in reply to the request. This attribute is set to false byQtWebKit when creating a cross-originXMLHttpRequest where withCredentials has not been set explicitly to true by the Javascript that created the request. Seehere for more information. (This value was introduced in 4.7.)
QNetworkRequest::AuthenticationReuseAttribute12Requests only, type:QVariant::Int (default:QNetworkRequest::Automatic) Indicates whether to use cached authorization credentials in the request, if available. If this is set toQNetworkRequest::Manual and the authentication mechanism is 'Basic' or 'Digest', Qt will not send an an 'Authorization' HTTP header with any cached credentials it may have for the request's URL. This attribute is set toQNetworkRequest::Manual byQtWebKit when creating a cross-originXMLHttpRequest where withCredentials has not been set explicitly to true by the Javascript that created the request. Seehere for more information. (This value was introduced in 4.7.)
QNetworkRequest::User1000Special type. Additional information can be passed inQVariants 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 ofQNetworkAccessManager.
QNetworkRequest::UserMax32767Special type. See User.

This enum was introduced or modified in Qt 4.7.

enum QNetworkRequest::CacheLoadControl

Controls the caching mechanism ofQNetworkAccessManager.

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 thatQNetworkRequest 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 aQDateTime representing the last modification date of the contents
QNetworkRequest::CookieHeader4corresponds to the HTTP Cookie header and contains aQList<QNetworkCookie> representing the cookies to be sent back to the server
QNetworkRequest::SetCookieHeader5corresponds to the HTTP Set-Cookie header and contains aQList<QNetworkCookie> representing the cookies sent by the server to be stored locally

See alsoheader(),setHeader(),rawHeader(), andsetRawHeader().

enum QNetworkRequest::LoadControl

Indicates if an aspect of the request's loading mechanism has been manually overridden, e.g. byQtWebKit.

ConstantValueDescription
QNetworkRequest::Automatic0default value: indicates default behaviour.
QNetworkRequest::Manual1indicates behaviour has been manually overridden.

This enum was introduced or modified in Qt 4.7.

enum QNetworkRequest::Priority

This enum lists the possible network request priorities.

ConstantValueDescription
QNetworkRequest::HighPriority1High priority
QNetworkRequest::NormalPriority3Normal priority
QNetworkRequest::LowPriority5Low priority

This enum was introduced or modified in Qt 4.7.

Member Function Documentation

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

Constructs aQNetworkRequest object withurl as the URL to be requested.

See alsourl() andsetUrl().

QNetworkRequest::QNetworkRequest(constQNetworkRequest & other)

Creates a copy ofother.

QNetworkRequest::~QNetworkRequest()

Disposes of theQNetworkRequest object.

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

Returns the attribute associated with the codecode. If the attribute has not been set, it returnsdefaultValue.

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

See alsosetAttribute() andQNetworkRequest::Attribute.

bool QNetworkRequest::hasRawHeader(constQByteArray & headerName) const

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

See alsorawHeader() andsetRawHeader().

QVariant QNetworkRequest::header(KnownHeaders header) const

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

See alsoKnownHeaders,rawHeader(), andsetHeader().

QObject * QNetworkRequest::originatingObject() const

Returns a reference to the object that initiated this network request; returns 0 if not set or the object has been destroyed.

This function was introduced in Qt 4.6.

See alsosetOriginatingObject().

Priority QNetworkRequest::priority() const

Return the priority of this request.

This function was introduced in Qt 4.7.

See alsosetPriority().

QByteArray QNetworkRequest::rawHeader(constQByteArray & headerName) const

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

Raw headers can be set withsetRawHeader() or withsetHeader().

See alsoheader() andsetRawHeader().

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 alsohasRawHeader() andrawHeader().

void QNetworkRequest::setAttribute(Attribute code, constQVariant & value)

Sets the attribute associated with codecode to be valuevalue. If the attribute is already set, the previous value is discarded. In special, ifvalue is an invalidQVariant, the attribute is unset.

See alsoattribute() andQNetworkRequest::Attribute.

void QNetworkRequest::setHeader(KnownHeaders header, constQVariant & value)

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

See alsoKnownHeaders,setRawHeader(), andheader().

void QNetworkRequest::setOriginatingObject(QObject * object)

Allows setting a reference to theobject initiating the request.

For exampleQtWebKit sets the originating object to theQWebFrame that initiated the request.

This function was introduced in Qt 4.6.

See alsooriginatingObject().

void QNetworkRequest::setPriority(Priority priority)

Set the priority of this request topriority.

Note:Thepriority is only a hint to the network access manager. It can use it or not. Currently it is used for HTTP to decide which request should be sent first to a server.

This function was introduced in Qt 4.7.

See alsopriority().

void QNetworkRequest::setRawHeader(constQByteArray & headerName, constQByteArray & headerValue)

Sets the headerheaderName to be of valueheaderValue. IfheaderName corresponds to a known header (seeQNetworkRequest::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 headerLastModifiedHeader to be theQDateTime 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 alsoKnownHeaders,setHeader(),hasRawHeader(), andrawHeader().

void QNetworkRequest::setSslConfiguration(constQSslConfiguration & config)

Sets this network request's SSL configuration to beconfig. The settings that apply are the private key, the local certificate, the SSL protocol (SSLv2, SSLv3, TLSv1 where applicable), the CA certificates 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 alsosslConfiguration() andQSslConfiguration::defaultConfiguration().

void QNetworkRequest::setUrl(constQUrl & url)

Sets the URL this network request is referring to to beurl.

See alsourl().

QSslConfiguration QNetworkRequest::sslConfiguration() const

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

See alsosetSslConfiguration().

QUrl QNetworkRequest::url() const

Returns the URL this network request is referring to.

See alsosetUrl().

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

Returns false if this object is not the same asother.

See alsooperator==().

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

Creates a copy ofother

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

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

See alsooperator!=().

© 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