QNetworkRequest 類保持要被發送的請求,采用 QNetworkAccessManager . 更多...
| 頭: |
#include <QNetworkRequest>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
|
| qmake: |
QT += network
|
| enum | 屬性 { HttpStatusCodeAttribute, HttpReasonPhraseAttribute, RedirectionTargetAttribute, ConnectionEncryptedAttribute, CacheLoadControlAttribute, …, UserMax } |
| enum | CacheLoadControl { AlwaysNetwork, PreferNetwork, PreferCache, AlwaysCache } |
| enum | KnownHeaders { ContentDispositionHeader, ContentTypeHeader, ContentLengthHeader, LocationHeader, LastModifiedHeader, …, ServerHeader } |
| enum | LoadControl { Automatic, Manual } |
| enum | Priority { HighPriority, NormalPriority, LowPriority } |
| enum | RedirectPolicy { ManualRedirectPolicy, NoLessSafeRedirectPolicy, SameOriginRedirectPolicy, UserVerifiedRedirectPolicy } |
| enum | TransferTimeoutConstant { DefaultTransferTimeoutConstant } |
| QNetworkRequest () | |
| QNetworkRequest (const QUrl & url ) | |
| QNetworkRequest (const QNetworkRequest & other ) | |
| ~QNetworkRequest () | |
| QVariant | attribute (QNetworkRequest::Attribute code , const QVariant & defaultValue = QVariant()) const |
(從 6.2 起)
qint64
|
decompressedSafetyCheckThreshold () const |
| bool | hasRawHeader (QAnyStringView headerName ) const |
| QVariant | header (QNetworkRequest::KnownHeaders header ) const |
(從 6.8 起)
QHttpHeaders
|
headers () const |
(從 6.5 起)
QHttp1Configuration
|
http1Configuration () const |
| QHttp2Configuration | http2Configuration () const |
| int | maximumRedirectsAllowed () const |
| QObject * | originatingObject () const |
| QString | peerVerifyName () const |
| QNetworkRequest::Priority | priority () const |
| QByteArray | rawHeader (QAnyStringView headerName ) const |
| QList<QByteArray> | rawHeaderList () const |
| void | setAttribute (QNetworkRequest::Attribute code , const QVariant & value ) |
(從 6.2 起)
void
|
setDecompressedSafetyCheckThreshold (qint64 threshold ) |
| void | setHeader (QNetworkRequest::KnownHeaders header , const QVariant & value ) |
(從 6.8 起)
void
|
setHeaders (QHttpHeaders && newHeaders ) |
(從 6.8 起)
void
|
setHeaders (const QHttpHeaders & newHeaders ) |
(從 6.5 起)
void
|
setHttp1Configuration (const QHttp1Configuration & configuration ) |
| void | setHttp2Configuration (const QHttp2Configuration & configuration ) |
| void | setMaximumRedirectsAllowed (int maxRedirectsAllowed ) |
| void | setOriginatingObject (QObject * object ) |
| void | setPeerVerifyName (const QString & peerName ) |
| void | setPriority (QNetworkRequest::Priority priority ) |
| void | setRawHeader (const QByteArray & headerName , const QByteArray & headerValue ) |
| void | setSslConfiguration (const QSslConfiguration & config ) |
| void | setTransferTimeout (int timeout ) |
(從 6.7 起)
void
|
setTransferTimeout (std::chrono::milliseconds duration = DefaultTransferTimeout) |
| void | setUrl (const QUrl & url ) |
| QSslConfiguration | sslConfiguration () const |
| void | swap (QNetworkRequest & other ) |
| int | transferTimeout () const |
(從 6.7 起)
std::chrono::milliseconds
|
transferTimeoutAsDuration () const |
| QUrl | url () const |
| bool | operator!= (const QNetworkRequest & other ) const |
| QNetworkRequest & | operator= (const QNetworkRequest & other ) |
| bool | operator== (const QNetworkRequest & other ) const |
| const std::chrono::std::chrono::milliseconds | DefaultTransferTimeout |
QNetworkRequest 屬於網絡訪問 API 且是保持通過網絡發送必要請求信息的類。它包含 URL 和一些可用於修改請求的輔助信息。
另請參閱 QNetworkReply and QNetworkAccessManager .
屬性代碼用於 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
|
0
|
僅迴復,類型: QMetaType::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
|
1
|
僅迴復,類型: QMetaType::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. 注意: The reason phrase is not used when using HTTP/2. |
QNetworkRequest::RedirectionTargetAttribute
|
2
|
僅迴復,類型: QMetaType::QUrl (no default) If present, it indicates that the server is redirecting the request to a different URL. The Network Access API does follow redirections by default, unless QNetworkRequest::ManualRedirectPolicy is used. Additionally, if QNetworkRequest::UserVerifiedRedirectPolicy is used, then this attribute will be set if the redirect was not followed. The returned URL might be relative. Use QUrl::resolved () to create an absolute URL out of it. |
QNetworkRequest::ConnectionEncryptedAttribute
|
3
|
僅迴復,類型: QMetaType::Bool (default: false) Indicates whether the data was obtained through an encrypted (secure) connection. |
QNetworkRequest::CacheLoadControlAttribute
|
4
|
僅請求,類型: QMetaType::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::CacheSaveControlAttribute
|
5
|
僅請求,類型: QMetaType::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
|
6
|
僅迴復,類型: QMetaType::Bool (default: false) Indicates whether the data was obtained from cache or not. |
QNetworkRequest::DoNotBufferUploadDataAttribute
|
7
|
僅請求,類型: QMetaType::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
|
8
|
僅請求,類型: QMetaType::Bool (default: false) Indicates whether the QNetworkAccessManager code is allowed to use HTTP pipelining with this request. |
QNetworkRequest::HttpPipeliningWasUsedAttribute
|
9
|
僅迴復,類型: QMetaType::Bool Indicates whether the HTTP pipelining was used for receiving this reply. |
QNetworkRequest::CustomVerbAttribute
|
10
|
僅請求,類型: QMetaType::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 QNetworkAccessManager::sendCustomRequest (). |
QNetworkRequest::CookieLoadControlAttribute
|
11
|
僅請求,類型: QMetaType::Int (default: QNetworkRequest::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
|
13
|
僅請求,類型: QMetaType::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 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
|
12
|
僅請求,類型: QMetaType::Int (default: QNetworkRequest::Automatic ) Indicates whether to use cached authorization credentials in the request, if available. If this is set to QNetworkRequest::Manual and the authentication mechanism is 'Basic' or 'Digest', Qt will not send an 'Authorization' HTTP header with any cached credentials it may have for the request's URL. This attribute is set to QNetworkRequest::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
|
17
|
類型: QMetaType::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. |
QNetworkRequest::Http2AllowedAttribute
|
19
|
僅請求,類型: QMetaType::Bool (default: true) Indicates whether the QNetworkAccessManager code is allowed to use HTTP/2 with this request. This applies to SSL requests or 'cleartext' HTTP/2 if Http2CleartextAllowedAttribute is set. |
QNetworkRequest::Http2WasUsedAttribute
|
20
|
僅迴復,類型: QMetaType::Bool (default: false) Indicates whether HTTP/2 was used for receiving this reply. (This value was introduced in 5.9.) |
QNetworkRequest::EmitAllUploadProgressSignalsAttribute
|
18
|
僅請求,類型: QMetaType::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::OriginalContentLengthAttribute
|
21
|
僅迴復,類型 QMetaType::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
|
22
|
僅請求,類型: QMetaType::Int , should be one of the QNetworkRequest::RedirectPolicy values (default: NoLessSafeRedirectPolicy ). (This value was introduced in 5.9.) |
QNetworkRequest::Http2DirectAttribute
|
23
|
僅請求,類型: QMetaType::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 with 'cleartext' HTTP/2 if Http2CleartextAllowedAttribute is set. 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 Http2AllowedAttribute and Http2DirectAttribute are set, Http2DirectAttribute takes priority. (This value was introduced in 5.11.) |
QNetworkRequest::AutoDeleteReplyOnFinishAttribute
|
25
|
僅請求,類型: QMetaType::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::ConnectionCacheExpiryTimeoutSecondsAttribute
|
26
|
僅請求,類型: QMetaType::Int To set when the TCP connections to a server (HTTP1 and HTTP2) should be closed after the last pending request had been processed. (This value was introduced in 6.3.) |
QNetworkRequest::Http2CleartextAllowedAttribute
|
27
|
僅請求,類型: QMetaType::Bool (default: false) If set, this attribute will tell QNetworkAccessManager to attempt an upgrade to HTTP/2 over cleartext (also known as h2c). Until Qt 7 the default value for this attribute can be overridden to true by setting the QT_NETWORK_H2C_ALLOWED environment variable. This attribute is ignored if the Http2AllowedAttribute is not set. (This value was introduced in 6.3.) |
QNetworkRequest::UseCredentialsAttribute
|
28
|
僅請求,類型: QMetaType::Bool (default: false) Indicates if the underlying XMLHttpRequest cross-site Access-Control requests should be made using credentials. Has no effect on same-origin requests. This only affects the WebAssembly platform. (This value was introduced in 6.5.) |
QNetworkRequest::FullLocalServerNameAttribute
|
29
|
Requests only, type: QMetaType::String Holds the full local server name to be used for the underlying QLocalSocket . This attribute is used by the QNetworkAccessManager to connect to a specific local server, when QLocalSocket 's behavior for a simple name isn't enough. The URL in the QNetworkRequest must still use unix+http: or local+http: scheme. And the hostname in the URL will be used for the Host header in the HTTP request. (This value was introduced in 6.8.) |
QNetworkRequest::User
|
1000
|
Special 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::UserMax
|
32767
|
特殊類型。見 User。 |
控製緩存機製為 QNetworkAccessManager .
| 常量 | 值 | 描述 |
|---|---|---|
QNetworkRequest::AlwaysNetwork
|
0
|
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
|
1
|
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
|
2
|
load from cache if available, otherwise load from network. Note that this can return possibly stale (but not expired) items from cache. |
QNetworkRequest::AlwaysCache
|
3
|
僅從緩存加載,指示齣錯若項未緩存 (即:離綫模式) |
已知頭類型列錶 QNetworkRequest 剖析。每個已知頭也以其完整 HTTP 名稱按原生形式錶示。
| 常量 | 值 | 描述 |
|---|---|---|
QNetworkRequest::ContentDispositionHeader
|
6
|
相當於 HTTP Content-Disposition 頭且包含包含處置類型 (例如:附件) 及參數 (例如:文件名) 的字符串。 |
QNetworkRequest::ContentTypeHeader
|
0
|
相當於 HTTP Content-Type 頭且包含包含媒體 MIME 類型及任何輔助數據 (例如:字符集) 的字符串。 |
QNetworkRequest::ContentLengthHeader
|
1
|
相當於 HTTP Content-Length 頭且包含以字節為單位的傳輸數據長度。 |
QNetworkRequest::LocationHeader
|
2
|
相當於 HTTP Location 頭且包含錶示數據實際位置的 URL,包括重定嚮情況下的目的地 URL。 |
QNetworkRequest::LastModifiedHeader
|
3
|
相當於 HTTP Last-Modified 頭且包含 QDateTime 錶示內容的最後修改日期。 |
QNetworkRequest::IfModifiedSinceHeader
|
9
|
相當於 HTTP If-Modified-Since 頭且包含 QDateTime 。它通常被添加到 QNetworkRequest 。服務器應發送 304 (未修改) 響應,若資源從此時間起未改變。 |
QNetworkRequest::ETagHeader
|
10
|
相當於 HTTP ETag 頭且包含 QString 錶示內容的最後修改狀態。 |
QNetworkRequest::IfMatchHeader
|
11
|
相當於 HTTP If-Match 頭且包含 QStringList 。它通常被添加到 QNetworkRequest 。服務器應發送 412 (前提條件失敗) 響應,若資源不匹配。 |
QNetworkRequest::IfNoneMatchHeader
|
12
|
相當於 HTTP If-None-Match 頭且包含 QStringList 。它通常被添加到 QNetworkRequest 。服務器應發送 304 (未修改) 響應,若資源匹配。 |
QNetworkRequest::CookieHeader
|
4
|
相當於 HTTP Cookie 頭且包含 QList < QNetworkCookie > 錶示要發送迴服務器的 Cookie。 |
QNetworkRequest::SetCookieHeader
|
5
|
相當於 HTTP Set-Cookie 頭且包含 QList < QNetworkCookie > 錶示由服務器發送給本地存儲的 Cookie。 |
QNetworkRequest::UserAgentHeader
|
7
|
由 HTTP 客戶端發送的 User-Agent 頭。 |
QNetworkRequest::ServerHeader
|
8
|
由 HTTP 客戶端收到的服務器 Header (頭)。 |
另請參閱 header (), setHeader (), rawHeader (),和 setRawHeader ().
指示是否已手動覆蓋請求的加載機製的某個方麵,如,通過 Qt WebKit。
| 常量 | 值 | 描述 |
|---|---|---|
QNetworkRequest::Automatic
|
0
|
默認值:指示默認行為。 |
QNetworkRequest::Manual
|
1
|
指示已手動覆寫行為。 |
此枚舉列錶可能的網絡請求優先級。
| 常量 | 值 | 描述 |
|---|---|---|
QNetworkRequest::HighPriority
|
1
|
高優先級 |
QNetworkRequest::NormalPriority
|
3
|
正常優先級 |
QNetworkRequest::LowPriority
|
5
|
低優先級 |
指示網絡訪問 API 是否應該自動遵循 HTTP 重定嚮響應。
| 常量 | 值 | 描述 |
|---|---|---|
QNetworkRequest::ManualRedirectPolicy
|
0
|
Not following any redirects. |
QNetworkRequest::NoLessSafeRedirectPolicy
|
1
|
Default value: Only "http"->"http", "http" -> "https" or "https" -> "https" redirects are allowed. |
QNetworkRequest::SameOriginRedirectPolicy
|
2
|
要求相同協議、主機及端口。注意:采用此策略 http://example.com 和 http://example.com:80 將失敗 (隱式/明確端口被認為是不匹配的)。 |
QNetworkRequest::UserVerifiedRedirectPolicy
|
3
|
客戶端決定是否遵循每個重定嚮通過處理 redirected() 信號,發射 redirectAllowed() 當 QNetworkReply 對象允許重定嚮或中止/完成以拒絕重定嚮。這可以被使用,例如,詢問用戶是否接受重定嚮,或基於某些特定 APP 配置來決定。 |
注意: 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.
可以被用於啓用帶預置值的傳輸超時的常量。
| 常量 | 值 | 描述 |
|---|---|---|
QNetworkRequest::DefaultTransferTimeoutConstant
|
30000
|
The transfer timeout in milliseconds. Used if setTransferTimeout () is called without an argument. |
另請參閱 QNetworkRequest::DefaultTransferTimeout .
構造不帶要請求 URL 的 QNetworkRequest 對象。使用 setUrl () 去設置一個。
[explicit]
QNetworkRequest::
QNetworkRequest
(const
QUrl
&
url
)
構造 QNetworkRequest 對象采用 url 作為要請求的 URL。
創建副本為 other .
[noexcept]
QNetworkRequest::
~QNetworkRequest
()
Disposes of the QNetworkRequest 對象。
返迴屬性關聯代碼 code . If the attribute has not been set, it returns defaultValue .
注意: 此函數不應用默認,列齣於 QNetworkRequest::Attribute .
另請參閱 setAttribute () 和 QNetworkRequest::Attribute .
[since 6.2]
qint64
QNetworkRequest::
decompressedSafetyCheckThreshold
() const
返迴用於存檔炸彈的校驗閾值。
If the decompressed size of a reply is smaller than this, Qt will simply decompress it, without further checking.
該函數在 Qt 6.2 引入。
另請參閱 setDecompressedSafetyCheckThreshold ().
返迴
true
若原生 Header (頭)
headerName
呈現在此網絡請求中。
注意: 在 Qt 6.7 之前,此函數接受 QByteArray 僅。
另請參閱 rawHeader () 和 setRawHeader ().
返迴已知網絡 Header (頭) 的值為 header 若它呈現在此請求中。若不存在,返迴 QVariant() (即:無效變體)。
另請參閱 KnownHeaders , rawHeader (),和 setHeader ().
[since 6.8]
QHttpHeaders
QNetworkRequest::
headers
() const
返迴在此網絡請求中設置的 Header (頭)。
該函數在 Qt 6.8 引入。
另請參閱 setHeaders ().
[since 6.5]
QHttp1Configuration
QNetworkRequest::
http1Configuration
() const
Returns the current parameters that QNetworkAccessManager is using for the underlying HTTP/1 connection of this request.
該函數在 Qt 6.5 引入。
另請參閱 setHttp1Configuration .
Returns the current parameters that QNetworkAccessManager is using for this request and its underlying HTTP/2 connection. This is either a configuration previously set by an application or a default configuration.
默認值 QNetworkAccessManager is using are:
By default, server push is disabled, Huffman compression and string indexing are enabled.
另請參閱 setHttp2Configuration .
Returns the maximum number of redirects allowed to be followed for this request.
另請參閱 setMaximumRedirectsAllowed ().
Returns a reference to the object that initiated this network request; returns
nullptr
if not set or the object has been destroyed.
另請參閱 setOriginatingObject ().
Returns the host name set for the certificate validation, as set by setPeerVerifyName . By default this returns a null string.
另請參閱 setPeerVerifyName .
返迴此請求的優先級。
另請參閱 setPriority ().
返迴 Header (頭) 的原生形式為 headerName 。若不存在這種 Header (頭),空 QByteArray 被返迴,可能難以區分存在但沒有內容的 Header 頭 (使用 hasRawHeader () 以確定 Header 頭是否存在)。
可以設置原生 Header (頭) 采用 setRawHeader () 或采用 setHeader ().
注意: 在 Qt 6.7 之前,此函數接受 QByteArray 僅。
另請參閱 header () 和 setRawHeader ().
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.
另請參閱 hasRawHeader () 和 rawHeader ().
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 () 和 QNetworkRequest::Attribute .
[since 6.2]
void
QNetworkRequest::
setDecompressedSafetyCheckThreshold
(
qint64
threshold
)
設置 threshold 為存檔炸彈校驗。
Some supported compression algorithms can, in a tiny compressed file, encode a spectacularly huge decompressed file. This is only possible if the decompressed content is extremely monotonous, which is seldom the case for real files being transmitted in good faith: files exercising such insanely high compression ratios are typically payloads of buffer-overrun attacks, or denial-of-service (by using up too much memory) attacks. Consequently, files that decompress to huge sizes, particularly from tiny compressed forms, are best rejected as suspected malware.
If a reply's decompressed size is bigger than this threshold (by default, 10 MiB, i.e. 10 * 1024 * 1024), Qt will check the compression ratio: if that is unreasonably large (40:1 for GZip and Deflate, or 100:1 for Brotli and ZStandard), the reply will be treated as an error. Setting the threshold to
-1
disables this check.
該函數在 Qt 6.2 引入。
另請參閱 decompressedSafetyCheckThreshold ().
Sets the value of the known header header 到 value ,覆蓋任何先前設置的 Header (頭)。此操作還設置等效原生 HTTP (頭)。
另請參閱 KnownHeaders , setRawHeader (),和 header ().
[since 6.8]
void
QNetworkRequest::
setHeaders
(
QHttpHeaders
&&
newHeaders
)
設置 newHeaders 作為此網絡請求中的 Header (頭),覆寫任何先前設置的頭。
若一些頭對應已知頭,將剖析這些值,且還會設置相應解析形式。
該函數在 Qt 6.8 引入。
另請參閱 headers () 和 KnownHeaders .
[since 6.8]
void
QNetworkRequest::
setHeaders
(const
QHttpHeaders
&
newHeaders
)
這是重載函數。
該函數在 Qt 6.8 引入。
[since 6.5]
void
QNetworkRequest::
setHttp1Configuration
(const
QHttp1Configuration
&
configuration
)
Sets request's HTTP/1 parameters from configuration .
該函數在 Qt 6.5 引入。
另請參閱 http1Configuration , QNetworkAccessManager ,和 QHttp1Configuration .
設置請求的 HTTP/2 參數從 configuration .
注意: The configuration must be set prior to making a request.
注意: HTTP/2 multiplexes several streams in a single HTTP/2 connection. This implies that QNetworkAccessManager will use the configuration found in the first request from a series of requests sent to the same host.
另請參閱 http2Configuration , QNetworkAccessManager ,和 QHttp2Configuration .
Sets the maximum number of redirects allowed to be followed for this request to maxRedirectsAllowed .
另請參閱 maximumRedirectsAllowed ().
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.
另請參閱 originatingObject ().
設置 peerName as host name for the certificate validation, instead of the one used for the TCP connection.
另請參閱 peerVerifyName .
把此請求的優先級設為 priority .
注意: 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.
另請參閱 priority ().
設置 Header (頭) headerName 到值 headerValue 。若 headerName 對應已知 Header (頭部) (見 QNetworkRequest::KnownHeaders ),原生格式將被剖析,相應 cooked 頭也將被設置。
例如:
request.setRawHeader(QByteArray("Last-Modified"), QByteArray("Sun, 06 Nov 1994 08:49:37 GMT"));
還將設置已知 Header LastModifiedHeader 為 QDateTime 剖析日期對象。
注意: 設置相同的頭 2 次覆蓋先前設置。要完成相同名稱多個 HTTP 頭的行為,應采用逗號 , 分隔它們並串聯這 2 個值,然後設置一個原生 Header (頭)。
注意: Since Qt 6.8, the header field names are normalized by converting them to lowercase.
另請參閱 KnownHeaders , setHeader (), hasRawHeader (),和 rawHeader ().
Sets this network request's SSL configuration to be config . The settings that apply are the private key, the local certificate, the TLS protocol (e.g. TLS 1.3), the CA certificates and the ciphers that the SSL backend is allowed to use.
另請參閱 sslConfiguration () 和 QSslConfiguration::defaultConfiguration ().
設置 timeout 作為傳輸超時 (以毫秒為單位)。
另請參閱 setTransferTimeout (std::chrono::milliseconds), transferTimeout (),和 transferTimeoutAsDuration ().
[since 6.7]
void
QNetworkRequest::
setTransferTimeout
(
std::chrono::milliseconds
duration
= DefaultTransferTimeout)
Sets the timeout duration to abort the transfer if no data is exchanged.
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 QNetworkRequest::DefaultTransferTimeout . If this function is not called, the timeout is disabled and has the value zero.
該函數在 Qt 6.7 引入。
另請參閱 transferTimeoutAsDuration ().
Sets the URL this network request is referring to be url .
另請參閱 url ().
Returns this network request's SSL configuration. By default this is the same as QSslConfiguration::defaultConfiguration ().
另請參閱 setSslConfiguration () 和 QSslConfiguration::defaultConfiguration ().
[noexcept]
void
QNetworkRequest::
swap
(
QNetworkRequest
&
other
)
交換此網絡請求與 other 。此操作很快且從不失敗。
返迴用於傳輸的超時 (以毫秒為單位)。
若
transferTimeoutAsDuration
().count() cannot be represented in
int
,此函數返迴
INT_MAX
/
INT_MIN
代替。
另請參閱 setTransferTimeout () 和 transferTimeoutAsDuration ().
[since 6.7]
std::chrono::milliseconds
QNetworkRequest::
transferTimeoutAsDuration
() const
Returns the timeout duration after which the transfer is aborted if no data is exchanged.
The default duration is zero, which means that the timeout is not used.
該函數在 Qt 6.7 引入。
另請參閱 setTransferTimeout (std::chrono::milliseconds).
返迴此網絡請求所引用的 URL。
另請參閱 setUrl ().
返迴
false
if this object is not the same as
other
.
另請參閱 operator== ().
創建副本為 other
返迴
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!= ().
The transfer timeout with QNetworkRequest::TransferTimeoutConstant milliseconds. Used if setTransferTimeout () is called without an argument.