内容表

上一话题

QNetworkReply

下一话题

QNetworkSession

QNetworkRequest

QNetworkRequest class holds a request to be sent with QNetworkAccessManager . 更多

Inheritance diagram of PySide2.QtNetwork.QNetworkRequest

概要

函数

详细描述

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.

class QNetworkRequest

QNetworkRequest(other)

QNetworkRequest(url)

param url

QUrl

param other

QNetworkRequest

构造 QNetworkRequest object with no URL to be requested. Use setUrl() to set one.

另请参阅

url() setUrl()

PySide2.QtNetwork.QNetworkRequest. KnownHeaders

已知头类型列表 QNetworkRequest 剖析。每个已知头也以其完整 HTTP 名称按原生形式表示。

常量

描述

QNetworkRequest.ContentDispositionHeader

相当于 HTTP Content-Disposition 头且包含包含处置类型 (例如:附件) 及参数 (例如:文件名) 的字符串。

QNetworkRequest.ContentTypeHeader

相当于 HTTP Content-Type 头且包含包含媒体 MIME 类型及任何辅助数据 (例如:字符集) 的字符串。

QNetworkRequest.ContentLengthHeader

相当于 HTTP Content-Length 头且包含以字节为单位的传输数据长度。

QNetworkRequest.LocationHeader

相当于 HTTP Location 头且包含表示数据实际位置的 URL,包括重定向情况下的目的地 URL。

QNetworkRequest.LastModifiedHeader

对应于 HTTP Last-Modified 头,并包含 QDateTime 表示内容的最后修改日期。

QNetworkRequest.IfModifiedSinceHeader

相当于 HTTP If-Modified-Since 头且包含 QDateTime 。它通常被添加到 QNetworkRequest 。服务器应发送 304 (未修改) 响应,若资源从此时间起未改变。

QNetworkRequest.ETagHeader

相当于 HTTP ETag 头且包含 QString 表示内容的最后修改状态。

QNetworkRequest.IfMatchHeader

相当于 HTTP If-Match 头且包含 QStringList 。它通常被添加到 QNetworkRequest 。服务器应发送 412 (前提条件失败) 响应,若资源不匹配。

QNetworkRequest.IfNoneMatchHeader

相当于 HTTP If-None-Match 头且包含 QStringList 。它通常被添加到 QNetworkRequest 。服务器应发送 304 (未修改) 响应,若资源匹配。

QNetworkRequest.CookieHeader

相当于 HTTP Cookie 头且包含 QList < QNetworkCookie > 表示要发送回服务器的 Cookie。

QNetworkRequest.SetCookieHeader

相当于 HTTP Set-Cookie 头且包含 QList < QNetworkCookie > 表示由服务器发送给本地存储的 Cookie。

QNetworkRequest.UserAgentHeader

由 HTTP 客户端发送的 User-Agent 头。

QNetworkRequest.ServerHeader

由 HTTP 客户端收到的服务器 Header 头。

PySide2.QtNetwork.QNetworkRequest. 属性

属性代码,用于 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.

常量

描述

QNetworkRequest.HttpStatusCodeAttribute

仅回复,类型: 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

仅回复,类型: 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

仅回复,类型: 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. Use resolved() to create an absolute URL out of it.

QNetworkRequest.ConnectionEncryptedAttribute

仅回复,类型: Bool (default: false) Indicates whether the data was obtained through an encrypted (secure) connection.

QNetworkRequest.CacheLoadControlAttribute

仅请求,类型: Int (default: PreferNetwork ) Controls how the cache should be accessed. The possible values are those of 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.CacheSaveControlAttribute

仅请求,类型: 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

仅回复,类型: Bool (default: false) Indicates whether the data was obtained from cache or not.

QNetworkRequest.DoNotBufferUploadDataAttribute

仅请求,类型: Bool (default: false) Indicates whether the QNetworkAccessManager code is allowed to buffer the upload data, e.g. when doing a HTTP POST. When using this flag with sequential upload data, the ContentLengthHeader header must be set.

QNetworkRequest.HttpPipeliningAllowedAttribute

仅请求,类型: Bool (default: false) Indicates whether the QNetworkAccessManager code is allowed to use HTTP pipelining with this request.

QNetworkRequest.HttpPipeliningWasUsedAttribute

仅回复,类型: Bool Indicates whether the HTTP pipelining was used for receiving this reply.

QNetworkRequest.CustomVerbAttribute

仅请求,类型: 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 calling sendCustomRequest() .

QNetworkRequest.CookieLoadControlAttribute

仅请求,类型: Int (default: 自动 ) 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

仅请求,类型: Int (default: 自动 ) 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

仅请求,类型: Int (default: 自动 ) Indicates whether to use cached authorization credentials in the request, if available. If this is set to 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 to Manual 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

类型: 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. The QNetworkSession ConnectInBackground property will be set according to this attribute.

QNetworkRequest.SpdyAllowedAttribute

仅请求,类型: Bool (default: false) Indicates whether the QNetworkAccessManager 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

仅回复,类型: Bool Indicates whether SPDY was used for receiving this reply. Obsolete, use Http2 instead of Spdy.

QNetworkRequest.Http2AllowedAttribute

仅请求,类型: Bool (default: false) Indicates whether the QNetworkAccessManager code is allowed to use HTTP/2 with this request. This applies to SSL requests or ‘cleartext’ HTTP/2.

QNetworkRequest.Http2WasUsedAttribute

仅回复,类型: 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

仅请求,类型: 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

仅请求,类型: 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

仅回复,类型 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

仅请求,类型: Int , should be one of the RedirectPolicy values (default: ManualRedirectPolicy ). This attribute obsoletes . (This value was introduced in 5.9.)

QNetworkRequest.Http2DirectAttribute

仅请求,类型: Bool (default: false) If set, this attribute will force QNetworkAccessManager 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

仅请求,类型: Bool (default: false) If set, this attribute will make QNetworkAccessManager delete the QNetworkReply 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

特殊类型。见 User。

PySide2.QtNetwork.QNetworkRequest. CacheLoadControl

控制缓存机制为 QNetworkAccessManager .

常量

描述

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

仅从缓存加载,指示出错若项未缓存 (即:离线模式)

PySide2.QtNetwork.QNetworkRequest. LoadControl

Indicates if an aspect of the request’s loading mechanism has been manually overridden, e.g. by Qt WebKit.

常量

描述

QNetworkRequest.Automatic

默认值:指示默认行为。

QNetworkRequest.Manual

指示行为已被手动覆盖。

New in version 4.7.

PySide2.QtNetwork.QNetworkRequest. Priority

此枚举列表可能的网络请求优先级。

常量

描述

QNetworkRequest.HighPriority

高优先级

QNetworkRequest.NormalPriority

正常优先级

QNetworkRequest.LowPriority

低优先级

New in version 4.7.

PySide2.QtNetwork.QNetworkRequest. RedirectPolicy

指示网络访问 API 是否应该自动遵循 HTTP 重定向响应。

常量

描述

QNetworkRequest.ManualRedirectPolicy

默认值:不遵循任何重定向。

QNetworkRequest.NoLessSafeRedirectPolicy

Only “http”->”http”, “http” -> “https” or “https” -> “https” redirects are allowed. Equivalent to setting the old FollowRedirectsAttribute 为 true

QNetworkRequest.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

客户端决定是否遵循每个重定向通过处理 redirected() 信号,发射 redirectAllowed() 当 QNetworkReply 对象允许重定向或中止/完成以拒绝重定向。这可以被使用,例如,询问用户是否接受重定向,或基于某些特定 APP 配置来决定。

New in version 5.9.

PySide2.QtNetwork.QNetworkRequest. TransferTimeoutConstant

可以被用于启用带预置值的传输超时的常量。

常量

描述

QNetworkRequest.DefaultTransferTimeoutConstant

传输超时 (以毫秒为单位)。使用,若不带自变量调用 setTimeout()。

New in version 5.15.

PySide2.QtNetwork.QNetworkRequest. attribute ( code [ , defaultValue=None ] )
参数
  • code 属性

  • defaultValue – object

返回类型

object

返回的属性关联代码 code . If the attribute has not been set, it returns defaultValue .

注意

此函数不应用默认,列出于 属性 .

另请参阅

setAttribute() 属性

PySide2.QtNetwork.QNetworkRequest. hasRawHeader ( headerName )
参数

headerName QByteArray

返回类型

bool

返回 true 若原生头 headerName 呈现在此网络请求中。

PySide2.QtNetwork.QNetworkRequest. header ( header )
参数

header KnownHeaders

返回类型

object

返回已知网络 Header 头的值为 header 若它呈现在此请求中。若不存在,返回 QVariant() (即:无效变体)。

另请参阅

KnownHeaders rawHeader() setHeader()

PySide2.QtNetwork.QNetworkRequest. maximumRedirectsAllowed ( )
返回类型

int

Returns the maximum number of redirects allowed to be followed for this request.

PySide2.QtNetwork.QNetworkRequest. __ne__ ( other )
参数

other QNetworkRequest

返回类型

bool

返回 false if this object is not the same as other .

另请参阅

operator==()

PySide2.QtNetwork.QNetworkRequest. __eq__ ( other )
参数

other QNetworkRequest

返回类型

bool

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

另请参阅

operator!=()

PySide2.QtNetwork.QNetworkRequest. originatingObject ( )
返回类型

QObject

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

PySide2.QtNetwork.QNetworkRequest. peerVerifyName ( )
返回类型

unicode

Returns the host name set for the certificate validation, as set by setPeerVerifyName . By default this returns a null string.

另请参阅

setPeerVerifyName

PySide2.QtNetwork.QNetworkRequest. priority ( )
返回类型

Priority

返回此请求的优先级。

另请参阅

setPriority()

PySide2.QtNetwork.QNetworkRequest. rawHeader ( headerName )
参数

headerName QByteArray

返回类型

QByteArray

返回 Header 头的原生形式为 headerName 。若不存在这种 Header 头,空 QByteArray 被返回,可能难以区分存在但没有内容的 Header 头 (使用 hasRawHeader() to find out if the header exists or not).

原生 Header 头可以被设置采用 setRawHeader() or with setHeader() .

PySide2.QtNetwork.QNetworkRequest. rawHeaderList ( )
返回类型

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.

PySide2.QtNetwork.QNetworkRequest. setAttribute ( code , 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 是无效 QVariant , the attribute is unset.

另请参阅

attribute() 属性

PySide2.QtNetwork.QNetworkRequest. setHeader ( header , value )
参数

Sets the value of the known header header to be value ,覆盖任何先前设置的 Header 头。此操作还设置等效原生 HTTP 头。

另请参阅

KnownHeaders setRawHeader() header()

PySide2.QtNetwork.QNetworkRequest. setMaximumRedirectsAllowed ( maximumRedirectsAllowed )
参数

maximumRedirectsAllowed int

Sets the maximum number of redirects allowed to be followed for this request to maxRedirectsAllowed .

PySide2.QtNetwork.QNetworkRequest. setOriginatingObject ( object )
参数

object 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.

PySide2.QtNetwork.QNetworkRequest. setPeerVerifyName ( peerName )
参数

peerName – unicode

peerName as host name for the certificate validation, instead of the one used for the TCP connection.

另请参阅

peerVerifyName

PySide2.QtNetwork.QNetworkRequest. setPriority ( priority )
参数

priority Priority

把此请求的优先级设为 priority .

注意

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.

另请参阅

priority()

PySide2.QtNetwork.QNetworkRequest. setRawHeader ( headerName , value )
参数
  • headerName QByteArray

  • value QByteArray

设置 Header 头 headerName 到值 headerValue 。若 headerName 对应已知 Header 头 (见 KnownHeaders ), the raw format will be parsed and the corresponding “cooked” header will be set as well.

例如:

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

还将设置已知 Header LastModifiedHeader to be the QDateTime 剖析日期对象。

注意

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.

PySide2.QtNetwork.QNetworkRequest. setSslConfiguration ( configuration )
参数

configuration 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.

PySide2.QtNetwork.QNetworkRequest. setTransferTimeout ( [ timeout=DefaultTransferTimeoutConstant ] )
参数

timeout int

timeout 作为传输超时 (以毫秒为单位)。

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.

另请参阅

transferTimeout

PySide2.QtNetwork.QNetworkRequest. setUrl ( url )
参数

url QUrl

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

另请参阅

url()

PySide2.QtNetwork.QNetworkRequest. sslConfiguration ( )
返回类型

QSslConfiguration

Returns this network request’s SSL configuration. By default this is the same as defaultConfiguration() .

PySide2.QtNetwork.QNetworkRequest. swap ( other )
参数

other QNetworkRequest

Swaps this network request with other 。此函数非常快,且从不失败。

PySide2.QtNetwork.QNetworkRequest. transferTimeout ( )
返回类型

int

返回用于传输的超时 (以毫秒为单位)。

此超时为 0 若 setTransferTimeout hasn’t been called, which means that the timeout is not used.

PySide2.QtNetwork.QNetworkRequest. url ( )
返回类型

QUrl

返回此网络请求所引用的 URL。

另请参阅

setUrl()