The QNetworkRequest class holds a request to be sent with QNetworkAccessManager . 更多...
| 頭: | #include <QNetworkRequest> |
| Since: | Qt 4.4 |
| enum | Attribute { HttpStatusCodeAttribute, HttpReasonPhraseAttribute, RedirectionTargetAttribute, ConnectionEncryptedAttribute, ..., UserMax } |
| enum | CacheLoadControl { AlwaysNetwork, PreferNetwork, PreferCache, AlwaysCache } |
| enum | KnownHeaders { ContentTypeHeader, ContentLengthHeader, LocationHeader, LastModifiedHeader, CookieHeader, SetCookieHeader } |
| enum | LoadControl { Automatic, Manual } |
| enum | Priority { HighPriority, NormalPriority, LowPriority } |
| QNetworkRequest (const QUrl & url = QUrl()) | |
| QNetworkRequest (const QNetworkRequest & other ) | |
| ~QNetworkRequest () | |
| QVariant | attribute (Attribute code , const QVariant & defaultValue = QVariant()) const |
| bool | hasRawHeader (const QByteArray & headerName ) const |
| QVariant | header (KnownHeaders header ) const |
| QObject * | originatingObject () const |
| 優先級 | priority () const |
| QByteArray | rawHeader (const QByteArray & headerName ) const |
| QList<QByteArray> | rawHeaderList () const |
| void | setAttribute (Attribute code , const QVariant & value ) |
| void | setHeader (KnownHeaders header , const QVariant & value ) |
| void | setOriginatingObject (QObject * object ) |
| void | setPriority (Priority priority ) |
| void | setRawHeader (const QByteArray & headerName , const QByteArray & headerValue ) |
| void | setSslConfiguration (const QSslConfiguration & config ) |
| void | setUrl (const QUrl & url ) |
| QSslConfiguration | sslConfiguration () const |
| QUrl | url () const |
| bool | operator!= (const QNetworkRequest & other ) const |
| QNetworkRequest & | operator= (const QNetworkRequest & other ) |
| bool | operator== (const QNetworkRequest & other ) const |
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager .
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.
另請參閱 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
|
僅迴復,類型: 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::HttpReasonPhraseAttribute
|
1
|
僅迴復,類型: 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::RedirectionTargetAttribute
|
2
|
僅迴復,類型: 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. Use QUrl::resolved () to create an absolute URL out of it. |
QNetworkRequest::ConnectionEncryptedAttribute
|
3
|
僅迴復,類型: QVariant::Bool (default: false) Indicates whether the data was obtained through an encrypted (secure) connection. |
QNetworkRequest::CacheLoadControlAttribute
|
4
|
僅請求,類型: QVariant::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
|
僅請求,類型: 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::SourceIsFromCacheAttribute
|
6
|
僅迴復,類型: QVariant::Bool (default: false) Indicates whether the data was obtained from cache or not. |
QNetworkRequest::DoNotBufferUploadDataAttribute
|
7
|
僅請求,類型: QVariant::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
|
僅請求,類型: QVariant::Bool (default: false) Indicates whether the QNetworkAccessManager code is allowed to use HTTP pipelining with this request. |
QNetworkRequest::HttpPipeliningWasUsedAttribute
|
9
|
僅迴復,類型: QVariant::Bool Indicates whether the HTTP pipelining was used for receiving this reply. |
QNetworkRequest::CustomVerbAttribute
|
10
|
僅請求,類型: 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 calling QNetworkAccessManager::sendCustomRequest (). |
QNetworkRequest::CookieLoadControlAttribute
|
11
|
僅請求,類型: QVariant::Int (default: QNetworkRequest::Automatic ) Indicates whether to send 'Cookie' headers in the request. This attribute is set to false by QtWebKit 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
|
僅請求,類型: 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 by QtWebKit 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
|
僅請求,類型: QVariant::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 an 'Authorization' HTTP header with any cached credentials it may have for the request's URL. This attribute is set to QNetworkRequest::Manual by QtWebKit 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::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。 |
該枚舉在 Qt 4.7 引入或被修改。
控製緩存機製為 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) |
QNetworkRequest::PreferNetwork
|
1
|
default value; load from the network if the cached entry is older than the network entry |
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::ContentTypeHeader
|
0
|
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
|
1
|
corresponds to the HTTP Content-Length header and contains the length in bytes of the data transmitted. |
QNetworkRequest::LocationHeader
|
2
|
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
|
3
|
corresponds to the HTTP Last-Modified header and contains a QDateTime representing the last modification date of the contents |
QNetworkRequest::CookieHeader
|
4
|
corresponds to the HTTP Cookie header and contains a QList < QNetworkCookie > representing the cookies to be sent back to the server |
QNetworkRequest::SetCookieHeader
|
5
|
corresponds to the HTTP Set-Cookie header and contains a QList < QNetworkCookie > representing the cookies sent by the server to be stored locally |
另請參閱 header (), setHeader (), rawHeader (),和 setRawHeader ().
Indicates if an aspect of the request's loading mechanism has been manually overridden, e.g. by QtWebKit .
| 常量 | 值 | 描述 |
|---|---|---|
QNetworkRequest::Automatic
|
0
|
默認值:指示默認行為。 |
QNetworkRequest::Manual
|
1
|
指示已手動覆寫行為。 |
該枚舉在 Qt 4.7 引入或被修改。
此枚舉列錶可能的網絡請求優先級。
| 常量 | 值 | 描述 |
|---|---|---|
QNetworkRequest::HighPriority
|
1
|
高優先級 |
QNetworkRequest::NormalPriority
|
3
|
正常優先級 |
QNetworkRequest::LowPriority
|
5
|
低優先級 |
該枚舉在 Qt 4.7 引入或被修改。
構造 QNetworkRequest 對象采用 url 作為要請求的 URL。
創建副本為 other .
Disposes of the QNetworkRequest 對象。
返迴屬性關聯代碼 code . If the attribute has not been set, it returns defaultValue .
Note: this function does not apply the defaults listed in QNetworkRequest::Attribute .
另請參閱 setAttribute () 和 QNetworkRequest::Attribute .
Returns true if the raw header headerName 呈現在此網絡請求中。
另請參閱 rawHeader () 和 setRawHeader ().
返迴已知網絡 Header (頭) 的值為 header 若它呈現在此請求中。若不存在,返迴 QVariant() (即:無效變體)。
另請參閱 KnownHeaders , rawHeader (),和 setHeader ().
Returns a reference to the object that initiated this network request; returns 0 if not set or the object has been destroyed.
該函數在 Qt 4.6 引入。
另請參閱 setOriginatingObject ().
返迴此請求的優先級。
該函數在 Qt 4.7 引入。
另請參閱 setPriority ().
返迴 Header (頭) 的原生形式為 headerName 。若不存在這種 Header (頭),空 QByteArray 被返迴,可能難以區分存在但沒有內容的 Header 頭 (使用 hasRawHeader () 以確定 Header 頭是否存在)。
可以設置原生 Header (頭) 采用 setRawHeader () 或采用 setHeader ().
另請參閱 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 .
Sets the value of the known header header 到 value ,覆蓋任何先前設置的 Header (頭)。此操作還設置等效原生 HTTP (頭)。
另請參閱 KnownHeaders , setRawHeader (),和 header ().
Allows setting a reference to the object initiating the request.
例如 QtWebKit sets the originating object to the QWebFrame that initiated the request.
該函數在 Qt 4.6 引入。
另請參閱 originatingObject ().
把此請求的優先級設為 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.
該函數在 Qt 4.7 引入。
另請參閱 priority ().
設置 Header (頭) headerName 到值 headerValue 。若 headerName 對應已知 Header (頭部) (見 QNetworkRequest::KnownHeaders ),原生格式將被剖析,相應 cooked 頭也將被設置。
例如:
request.setRawHeader("Last-Modified", "Sun, 06 Nov 1994 08:49:37 GMT");
還將設置已知 Header LastModifiedHeader 為 QDateTime 剖析日期對象。
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.
另請參閱 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 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.
另請參閱 sslConfiguration () 和 QSslConfiguration::defaultConfiguration ().
Sets the URL this network request is referring to to be url .
另請參閱 url ().
Returns this network request's SSL configuration. By default, no SSL settings are specified.
另請參閱 setSslConfiguration ().
返迴此網絡請求所引用的 URL。
另請參閱 setUrl ().
Returns false if this object is not the same as other .
另請參閱 operator== ().
創建副本為 other
Returns 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!= ().