6.0.0-rc4Source

QNetworkRequest Class

The QNetworkRequest class describes a network request: a URL plus headers and transfer settings. More…

Header#include <QNetworkRequest>
CMaketarget_link_libraries(app PRIVATE Nt::Network)
ModuleNt Network C++ Classes

List of all members, including inherited members

Public Types

Public Functions

QNetworkRequest()
QNetworkRequest(const QUrl &url)
QUrlurl() const
voidsetUrl(const QUrl &url)
QByteArrayheader(KnownHeaders header) const
voidsetHeader(KnownHeaders header, const QByteArray &value)
boolhasRawHeader(const QByteArray &headerName) const
QList<QByteArray>rawHeaderList() const
QByteArrayrawHeader(const QByteArray &headerName) const
voidsetRawHeader(const QByteArray &headerName, const QByteArray &headerValue)
QVariantattribute(Attribute code, const QVariant &defaultValue = QVariant()) const
voidsetAttribute(Attribute code, const QVariant &value)
RedirectPolicyredirectPolicy() const
voidsetRedirectPolicy(RedirectPolicy policy)
intmaximumRedirectsAllowed() const
voidsetMaximumRedirectsAllowed(int maximumRedirectsAllowed)
inttransferTimeout() const
voidsetTransferTimeout(int timeout)
QSslConfigurationsslConfiguration() const
voidsetSslConfiguration(const QSslConfiguration &configuration)

Detailed Description

See also QNetworkAccessManager and QNetworkReply.

Differences from Qt

Attributes are stored and returned, but none of them changes how the request is sent; setRedirectPolicy(), setMaximumRedirectsAllowed() and setTransferTimeout() cover the common settings. Known headers are read and written as QByteArray rather than QVariant. There is no priority or HTTP/2 setting, and no UserVerifiedRedirectPolicy.

Member Type Documentation

enum QNetworkRequest::Attribute

Keys for the values attached to a request with setAttribute() or reported on a reply with QNetworkReply::attribute(). Only the first group is produced by a reply; the rest are stored on a request but have no effect.

ConstantDescription
QNetworkRequest::HttpStatusCodeAttributeThe HTTP status code, as an int. Reply only.
QNetworkRequest::HttpReasonPhraseAttributeThe HTTP reason phrase, as a QByteArray. Reply only.
QNetworkRequest::RedirectionTargetAttributeThe Location of a redirect that was not followed, as a QUrl, possibly relative. Reply only.
QNetworkRequest::ConnectionEncryptedAttributetrue if the reply came over TLS. Reply only.
QNetworkRequest::SourceIsFromCacheAttributeAlways false, as there is no cache. Reply only.
QNetworkRequest::HttpPipeliningWasUsedAttributeAlways false. Reply only.
QNetworkRequest::Http2WasUsedAttributeAlways false. Reply only.
QNetworkRequest::CacheLoadControlAttributeStored only.
QNetworkRequest::CacheSaveControlAttributeStored only.
QNetworkRequest::DoNotBufferUploadDataAttributeStored only.
QNetworkRequest::HttpPipeliningAllowedAttributeStored only.
QNetworkRequest::CustomVerbAttributeStored only.
QNetworkRequest::CookieLoadControlAttributeStored only.
QNetworkRequest::AuthenticationReuseAttributeStored only.
QNetworkRequest::CookieSaveControlAttributeStored only.
QNetworkRequest::MaximumDownloadBufferSizeAttributeStored only.
QNetworkRequest::DownloadBufferAttributeStored only.
QNetworkRequest::SynchronousRequestAttributeStored only.
QNetworkRequest::BackgroundRequestAttributeStored only.
QNetworkRequest::EmitAllUploadProgressSignalsAttributeStored only.
QNetworkRequest::Http2AllowedAttributeStored only.
QNetworkRequest::OriginalContentLengthAttributeStored only.
QNetworkRequest::RedirectPolicyAttributeStored only; use setRedirectPolicy().
QNetworkRequest::Http2DirectAttributeStored only.
QNetworkRequest::ResourceTypeAttributeStored only.
QNetworkRequest::AutoDeleteReplyOnFinishAttributeStored only.
QNetworkRequest::ConnectionCacheExpiryTimeoutSecondsAttributeStored only.
QNetworkRequest::Http2CleartextAllowedAttributeStored only.
QNetworkRequest::UseCredentialsAttributeStored only.
QNetworkRequest::UserThe first code reserved for applications.
QNetworkRequest::UserMaxThe last code reserved for applications.

enum QNetworkRequest::KnownHeaders

Common HTTP headers.

ConstantDescription
QNetworkRequest::ContentTypeHeaderContent-Type
QNetworkRequest::ContentLengthHeaderContent-Length
QNetworkRequest::LocationHeaderLocation
QNetworkRequest::LastModifiedHeaderLast-Modified
QNetworkRequest::CookieHeaderCookie
QNetworkRequest::SetCookieHeaderSet-Cookie
QNetworkRequest::ContentDispositionHeaderContent-Disposition
QNetworkRequest::UserAgentHeaderUser-Agent
QNetworkRequest::ServerHeaderServer
QNetworkRequest::IfModifiedSinceHeaderIf-Modified-Since
QNetworkRequest::ETagHeaderETag
QNetworkRequest::IfMatchHeaderIf-Match
QNetworkRequest::IfNoneMatchHeaderIf-None-Match

enum QNetworkRequest::RedirectPolicy

Selects what happens when the server redirects a request.

ConstantDescription
QNetworkRequest::ManualRedirectPolicyRedirects are not followed; the 3xx reply is returned.
QNetworkRequest::NoLessSafeRedirectPolicyRedirects are followed, but not to a less secure scheme.
QNetworkRequest::SameOriginRedirectPolicyOnly redirects to the same scheme, host and port are followed.

Member Function Documentation

QNetworkRequest::QNetworkRequest()

Constructs a request with no URL.

[explicit] QNetworkRequest::QNetworkRequest(const QUrl &url)

Constructs a request for url.

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

Returns the value stored for code, or defaultValue if none is set.

See also setAttribute().

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

Returns true if the header headerName is set. Names are not case sensitive.

See also rawHeader().

Returns the value of the known header, or an empty array if it is unset.

See also setHeader().

int QNetworkRequest::maximumRedirectsAllowed() const

Returns the most redirects that are followed. The default is 50.

See also setMaximumRedirectsAllowed().

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

Returns the value of the header headerName, or an empty array if it is unset.

See also setRawHeader().

QList<QByteArray> QNetworkRequest::rawHeaderList() const

Returns the names of the headers that are set.

RedirectPolicy QNetworkRequest::redirectPolicy() const

Returns the redirect policy. The default is NoLessSafeRedirectPolicy.

See also setRedirectPolicy().

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

Stores value for code, replacing any previous value. An invalid QVariant removes the attribute.

See also attribute().

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

Sets the known header to value.

See also header().

void QNetworkRequest::setMaximumRedirectsAllowed(int maximumRedirectsAllowed)

Sets the most redirects that are followed to maximumRedirectsAllowed.

See also maximumRedirectsAllowed().

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

Sets the header headerName to headerValue, replacing any previous value. An empty value removes the header. A name or value containing line breaks makes the request fail with ProtocolInvalidOperationError, as it could otherwise inject extra headers.

See also rawHeader().

void QNetworkRequest::setRedirectPolicy(RedirectPolicy policy)

Sets the redirect policy to policy.

See also redirectPolicy().

void QNetworkRequest::setSslConfiguration(const QSslConfiguration &configuration)

Sets the TLS settings for this request to configuration, for example to trust a private CA.

See also sslConfiguration().

void QNetworkRequest::setTransferTimeout(int timeout)

Fails the request with TimeoutError if no data moves for timeout milliseconds.

See also transferTimeout().

void QNetworkRequest::setUrl(const QUrl &url)

Sets the URL to url.

See also url().

QSslConfiguration QNetworkRequest::sslConfiguration() const

Returns the TLS settings for this request.

See also setSslConfiguration().

int QNetworkRequest::transferTimeout() const

Returns the inactivity timeout in milliseconds; 0 uses the manager's.

See also setTransferTimeout().

QUrl QNetworkRequest::url() const

Returns the URL.

See also setUrl().