QNetworkRequest¶
The
QNetworkRequest
class holds a request to be sent withQNetworkAccessManager
. More…
Synopsis¶
Functions¶
def
__eq__
(other)def
__ne__
(other)def
attribute
(code[, defaultValue=None])def
hasRawHeader
(headerName)def
header
(header)def
maximumRedirectsAllowed
()def
originatingObject
()def
peerVerifyName
()def
priority
()def
rawHeader
(headerName)def
rawHeaderList
()def
setAttribute
(code, value)def
setHeader
(header, value)def
setMaximumRedirectsAllowed
(maximumRedirectsAllowed)def
setOriginatingObject
(object)def
setPeerVerifyName
(peerName)def
setPriority
(priority)def
setRawHeader
(headerName, value)def
setSslConfiguration
(configuration)def
setTransferTimeout
([timeout=DefaultTransferTimeoutConstant])def
setUrl
(url)def
sslConfiguration
()def
swap
(other)def
transferTimeout
()def
url
()
Detailed Description¶
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
- class PySide2.QtNetwork.QNetworkRequest¶
PySide2.QtNetwork.QNetworkRequest(other)
PySide2.QtNetwork.QNetworkRequest(url)
- param url:
- param other:
Constructs a
QNetworkRequest
object with no URL to be requested. UsesetUrl()
to set one.
- PySide2.QtNetwork.QNetworkRequest.KnownHeaders¶
List of known header types that
QNetworkRequest
parses. Each known header is also represented in raw form with its full HTTP name.Constant
Description
QNetworkRequest.ContentDispositionHeader
Corresponds to the HTTP Content-Disposition header and contains a string containing the disposition type (for instance, attachment) and a parameter (for instance, filename).
QNetworkRequest.ContentTypeHeader
Corresponds to the HTTP Content-Type header and contains a string containing the media (MIME) type and any auxiliary data (for instance, charset).
QNetworkRequest.ContentLengthHeader
Corresponds to the HTTP Content-Length header and contains the length in bytes of the data transmitted.
QNetworkRequest.LocationHeader
Corresponds 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.LastModifiedHeader
Corresponds to the HTTP Last-Modified header and contains a
QDateTime
representing the last modification date of the contents.QNetworkRequest.IfModifiedSinceHeader
Corresponds to the HTTP If-Modified-Since header and contains a
QDateTime
. It is usually added to aQNetworkRequest
. The server shall send a 304 (Not Modified) response if the resource has not changed since this time.QNetworkRequest.ETagHeader
Corresponds to the HTTP ETag header and contains a
QString
representing the last modification state of the contents.QNetworkRequest.IfMatchHeader
Corresponds to the HTTP If-Match header and contains a
QStringList
. It is usually added to aQNetworkRequest
. The server shall send a 412 (Precondition Failed) response if the resource does not match.QNetworkRequest.IfNoneMatchHeader
Corresponds to the HTTP If-None-Match header and contains a
QStringList
. It is usually added to aQNetworkRequest
. The server shall send a 304 (Not Modified) response if the resource does match.QNetworkRequest.CookieHeader
Corresponds to the HTTP Cookie header and contains a
QList
<QNetworkCookie
> representing the cookies to be sent back to the server.QNetworkRequest.SetCookieHeader
Corresponds to the HTTP Set-Cookie header and contains a
QList
<QNetworkCookie
> representing the cookies sent by the server to be stored locally.QNetworkRequest.UserAgentHeader
The User-Agent header sent by HTTP clients.
QNetworkRequest.ServerHeader
The Server header received by HTTP clients.
See also
- PySide2.QtNetwork.QNetworkRequest.Attribute¶
Attribute codes for the
QNetworkRequest
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, the
QVariant
types associated, the default value if said attribute is missing and whether it’s used in requests or replies.Constant
Description
QNetworkRequest.HttpStatusCodeAttribute
Replies only, type:
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.HttpReasonPhraseAttribute
Replies only, type:
QByteArray
(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.RedirectionTargetAttribute
Replies only, type:
QUrl
(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: the application can determine if the requested redirection should be allowed, according to its security policies, or it can set to true (in which case the redirection will be followed and this attribute will not be present in the reply). The returned URL might be relative. Useresolved()
to create an absolute URL out of it.QNetworkRequest.ConnectionEncryptedAttribute
Replies only, type:
Bool
(default: false) Indicates whether the data was obtained through an encrypted (secure) connection.QNetworkRequest.CacheLoadControlAttribute
Requests only, type:
Int
(default:PreferNetwork
) Controls how the cache should be accessed. The possible values are those ofCacheLoadControl
. 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.CacheSaveControlAttribute
Requests only, type:
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.SourceIsFromCacheAttribute
Replies only, type:
Bool
(default: false) Indicates whether the data was obtained from cache or not.QNetworkRequest.DoNotBufferUploadDataAttribute
Requests only, type:
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.HttpPipeliningAllowedAttribute
Requests only, type:
Bool
(default: false) Indicates whether theQNetworkAccessManager
code is allowed to use HTTP pipelining with this request.QNetworkRequest.HttpPipeliningWasUsedAttribute
Replies only, type:
Bool
Indicates whether the HTTP pipelining was used for receiving this reply.QNetworkRequest.CustomVerbAttribute
Requests only, type:
QByteArray
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 callingsendCustomRequest()
.QNetworkRequest.CookieLoadControlAttribute
Requests only, type:
Int
(default:Automatic
) Indicates whether to send ‘Cookie’ headers in the request. This attribute is set to false by Qt WebKit when creating a cross-origin XMLHttpRequest where withCredentials has not been set explicitly to true by the Javascript that created the request. See here for more information. (This value was introduced in 4.7.)QNetworkRequest.CookieSaveControlAttribute
Requests only, type:
Int
(default:Automatic
) Indicates whether to save ‘Cookie’ headers received from the server in reply to the request. This attribute is set to false by Qt WebKit when creating a cross-origin XMLHttpRequest where withCredentials has not been set explicitly to true by the Javascript that created the request. See here for more information. (This value was introduced in 4.7.)QNetworkRequest.AuthenticationReuseAttribute
Requests only, type:
Int
(default:Automatic
) Indicates whether to use cached authorization credentials in the request, if available. If this is set toManual
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 toManual
by Qt WebKit when creating a cross-origin XMLHttpRequest where withCredentials has not been set explicitly to true by the Javascript that created the request. See here for more information. (This value was introduced in 4.7.)QNetworkRequest.BackgroundRequestAttribute
Type:
Bool
(default: false) Indicates that this is a background transfer, rather than a user initiated transfer. Depending on the platform, background transfers may be subject to different policies. TheQNetworkSession
ConnectInBackground property will be set according to this attribute.QNetworkRequest.SpdyAllowedAttribute
Requests only, type:
Bool
(default: false) Indicates whether theQNetworkAccessManager
code is allowed to use SPDY with this request. This applies only to SSL requests, and depends on the server supporting SPDY. Obsolete, use Http2 instead of Spdy.QNetworkRequest.SpdyWasUsedAttribute
Replies only, type:
Bool
Indicates whether SPDY was used for receiving this reply. Obsolete, use Http2 instead of Spdy.QNetworkRequest.Http2AllowedAttribute
Requests only, type:
Bool
(default: false) Indicates whether theQNetworkAccessManager
code is allowed to use HTTP/2 with this request. This applies to SSL requests or ‘cleartext’ HTTP/2.QNetworkRequest.Http2WasUsedAttribute
Replies only, type:
Bool
(default: false) Indicates whether HTTP/2 was used for receiving this reply. (This value was introduced in 5.9.)QNetworkRequest.HTTP2AllowedAttribute
Obsolete alias for .
QNetworkRequest.HTTP2WasUsedAttribute
Obsolete alias for .
QNetworkRequest.EmitAllUploadProgressSignalsAttribute
Requests only, type:
Bool
(default: false) Indicates whether all upload signals should be emitted. By default, the uploadProgress signal is emitted only in 100 millisecond intervals. (This value was introduced in 5.5.)QNetworkRequest.FollowRedirectsAttribute
Requests only, type:
Bool
(default: false) Indicates whether the Network Access API should automatically follow a HTTP redirect response or not. Currently redirects that are insecure, that is redirecting from “https” to “http” protocol, are not allowed. (This value was introduced in 5.6.)QNetworkRequest.OriginalContentLengthAttribute
Replies only, type
Int
Holds the original content-length attribute before being invalidated and removed from the header when the data is compressed and the request was marked to be decompressed automatically. (This value was introduced in 5.9.)QNetworkRequest.RedirectPolicyAttribute
Requests only, type:
Int
, should be one of theRedirectPolicy
values (default:ManualRedirectPolicy
). This attribute obsoletes . (This value was introduced in 5.9.)QNetworkRequest.Http2DirectAttribute
Requests only, type:
Bool
(default: false) If set, this attribute will forceQNetworkAccessManager
to use HTTP/2 protocol without initial HTTP/2 protocol negotiation. Use of this attribute implies prior knowledge that a particular server supports HTTP/2. The attribute works with SSL or ‘cleartext’ HTTP/2. If a server turns out to not support HTTP/2, when HTTP/2 direct was specified,QNetworkAccessManager
gives up, without attempting to fall back to HTTP/1.1. If both and are set, takes priority. (This value was introduced in 5.11.)QNetworkRequest.AutoDeleteReplyOnFinishAttribute
Requests only, type:
Bool
(default: false) If set, this attribute will makeQNetworkAccessManager
delete theQNetworkReply
after having emitted “finished”. (This value was introduced in 5.14.)QNetworkRequest.User
Special type. Additional information can be passed in QVariants with types ranging from User to . 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.UserMax
Special type. See User.
- PySide2.QtNetwork.QNetworkRequest.CacheLoadControl¶
Controls the caching mechanism of
QNetworkAccessManager
.Constant
Description
QNetworkRequest.AlwaysNetwork
always load from network and do not check if the cache has a valid entry (similar to the “Reload” feature in browsers); in addition, force intermediate caches to re-validate.
QNetworkRequest.PreferNetwork
default value; load from the network if the cached entry is older than the network entry. This will never return stale data from the cache, but revalidate resources that have become stale.
QNetworkRequest.PreferCache
load from cache if available, otherwise load from network. Note that this can return possibly stale (but not expired) items from cache.
QNetworkRequest.AlwaysCache
only load from cache, indicating error if the item was not cached (i.e., off-line mode)
- PySide2.QtNetwork.QNetworkRequest.LoadControl¶
Indicates if an aspect of the request’s loading mechanism has been manually overridden, e.g. by Qt WebKit.
Constant
Description
QNetworkRequest.Automatic
default value: indicates default behaviour.
QNetworkRequest.Manual
indicates behaviour has been manually overridden.
New in version 4.7.
- PySide2.QtNetwork.QNetworkRequest.Priority¶
This enum lists the possible network request priorities.
Constant
Description
QNetworkRequest.HighPriority
High priority
QNetworkRequest.NormalPriority
Normal priority
QNetworkRequest.LowPriority
Low priority
New in version 4.7.
- PySide2.QtNetwork.QNetworkRequest.RedirectPolicy¶
Indicates whether the Network Access API should automatically follow a HTTP redirect response or not.
Constant
Description
QNetworkRequest.ManualRedirectPolicy
Default value: not following any redirects.
QNetworkRequest.NoLessSafeRedirectPolicy
Only “http”->”http”, “http” -> “https” or “https” -> “https” redirects are allowed. Equivalent to setting the old
FollowRedirectsAttribute
to trueQNetworkRequest.SameOriginRedirectPolicy
Require the same protocol, host and port. Note, http://example.com and http://example.com:80 will fail with this policy (implicit/explicit ports are considered to be a mismatch).
QNetworkRequest.UserVerifiedRedirectPolicy
Client decides whether to follow each redirect by handling the redirected() signal, emitting redirectAllowed() on the
QNetworkReply
object to allow the redirect or aborting/finishing it to reject the redirect. This can be used, for example, to ask the user whether to accept the redirect, or to decide based on some app-specific configuration.Note
When Qt handles redirects it will, for legacy and compatibility reasons, issue the redirected request using GET when the server returns a 301 or 302 response, regardless of the original method used, unless it was HEAD.
New in version 5.9.
- PySide2.QtNetwork.QNetworkRequest.TransferTimeoutConstant¶
A constant that can be used for enabling transfer timeouts with a preset value.
Constant
Description
QNetworkRequest.DefaultTransferTimeoutConstant
The transfer timeout in milliseconds. Used if setTimeout() is called without an argument.
New in version 5.15.
- PySide2.QtNetwork.QNetworkRequest.attribute(code[, defaultValue=None])¶
- Parameters:
code – Attribute
defaultValue – object
- Return type:
object
Returns the attribute associated with the code
code
. If the attribute has not been set, it returnsdefaultValue
.Note
This function does not apply the defaults listed in
Attribute
.See also
setAttribute()
Attribute
- PySide2.QtNetwork.QNetworkRequest.hasRawHeader(headerName)¶
- Parameters:
headerName –
PySide2.QtCore.QByteArray
- Return type:
bool
Returns
true
if the raw headerheaderName
is present in this network request.See also
- PySide2.QtNetwork.QNetworkRequest.header(header)¶
- Parameters:
header –
KnownHeaders
- Return type:
object
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()
setHeader()
- PySide2.QtNetwork.QNetworkRequest.maximumRedirectsAllowed()¶
- Return type:
int
Returns the maximum number of redirects allowed to be followed for this request.
See also
- PySide2.QtNetwork.QNetworkRequest.__ne__(other)¶
- Parameters:
- Return type:
bool
Returns
false
if this object is not the same asother
.See also
operator==()
- PySide2.QtNetwork.QNetworkRequest.__eq__(other)¶
- Parameters:
- Return type:
bool
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 also
operator!=()
- PySide2.QtNetwork.QNetworkRequest.originatingObject()¶
- Return type:
Returns a reference to the object that initiated this network request; returns
None
if not set or the object has been destroyed.See also
- PySide2.QtNetwork.QNetworkRequest.peerVerifyName()¶
- Return type:
str
Returns the host name set for the certificate validation, as set by
setPeerVerifyName
. By default this returns a null string.See also
- PySide2.QtNetwork.QNetworkRequest.priority()¶
- Return type:
Return the priority of this request.
See also
- PySide2.QtNetwork.QNetworkRequest.rawHeader(headerName)¶
- Parameters:
headerName –
PySide2.QtCore.QByteArray
- Return type:
Returns the raw form of header
headerName
. 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 with
setRawHeader()
or withsetHeader()
.See also
- PySide2.QtNetwork.QNetworkRequest.rawHeaderList()¶
- Return type:
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
- PySide2.QtNetwork.QNetworkRequest.setAttribute(code, value)¶
- Parameters:
code – Attribute
value – object
Sets the attribute associated with code
code
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 also
attribute()
Attribute
- PySide2.QtNetwork.QNetworkRequest.setHeader(header, value)¶
- Parameters:
header –
KnownHeaders
value – object
Sets the value of the known header
header
to bevalue
, overriding any previously set headers. This operation also sets the equivalent raw HTTP header.See also
KnownHeaders
setRawHeader()
header()
- PySide2.QtNetwork.QNetworkRequest.setMaximumRedirectsAllowed(maximumRedirectsAllowed)¶
- Parameters:
maximumRedirectsAllowed – int
Sets the maximum number of redirects allowed to be followed for this request to
maxRedirectsAllowed
.See also
- PySide2.QtNetwork.QNetworkRequest.setOriginatingObject(object)¶
- Parameters:
object –
PySide2.QtCore.QObject
Allows setting a reference to the
object
initiating the request.For example Qt WebKit sets the originating object to the QWebFrame that initiated the request.
See also
- PySide2.QtNetwork.QNetworkRequest.setPeerVerifyName(peerName)¶
- Parameters:
peerName – str
Sets
peerName
as host name for the certificate validation, instead of the one used for the TCP connection.See also
- PySide2.QtNetwork.QNetworkRequest.setPriority(priority)¶
- Parameters:
priority –
Priority
Set the priority of this request to
priority
.Note
The
priority
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.See also
- PySide2.QtNetwork.QNetworkRequest.setRawHeader(headerName, value)¶
- Parameters:
headerName –
PySide2.QtCore.QByteArray
value –
PySide2.QtCore.QByteArray
Sets the header
headerName
to be of valueheaderValue
. IfheaderName
corresponds to a known header (seeKnownHeaders
), 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 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 also
KnownHeaders
setHeader()
hasRawHeader()
rawHeader()
- PySide2.QtNetwork.QNetworkRequest.setSslConfiguration(configuration)¶
- Parameters:
configuration –
PySide2.QtNetwork.QSslConfiguration
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.0 where applicable), the CA certificates and the ciphers that the SSL backend is allowed to use.See also
- PySide2.QtNetwork.QNetworkRequest.setTransferTimeout([timeout=DefaultTransferTimeoutConstant])¶
- Parameters:
timeout – int
Sets
timeout
as the transfer timeout in milliseconds.Transfers are aborted if no bytes are transferred before the timeout expires. Zero means no timer is set. If no argument is provided, the timeout is
DefaultTransferTimeoutConstant
. If this function is not called, the timeout is disabled and has the value zero.See also
- PySide2.QtNetwork.QNetworkRequest.setUrl(url)¶
- Parameters:
url –
PySide2.QtCore.QUrl
Sets the URL this network request is referring to be
url
.See also
- PySide2.QtNetwork.QNetworkRequest.sslConfiguration()¶
- Return type:
Returns this network request’s SSL configuration. By default this is the same as
defaultConfiguration()
.
- PySide2.QtNetwork.QNetworkRequest.swap(other)¶
- Parameters:
Swaps this network request with
other
. This function is very fast and never fails.
- PySide2.QtNetwork.QNetworkRequest.transferTimeout()¶
- Return type:
int
Returns the timeout used for transfers, in milliseconds.
This timeout is zero if
setTransferTimeout
hasn’t been called, which means that the timeout is not used.See also
- PySide2.QtNetwork.QNetworkRequest.url()¶
- Return type:
Returns the URL this network request is referring to.
See also
© 2022 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 the GNU 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.