QNetworkReplyclass contains the data and headers for a request sent withQNetworkAccessManager. 更多 …
def
attribute
(code)
def
error
()
def
hasRawHeader
(headerName)
def
header
(header)
def
ignoreSslErrors
(errors)
def
isFinished
()
def
isRunning
()
def
manager
()
def
operation
()
def
rawHeader
(headerName)
def
rawHeaderList
()
def
rawHeaderPairs
()
def
readBufferSize
()
def
request
()
def
setAttribute
(code, value)
def
setError
(errorCode, errorString)
def
setFinished
(arg__1)
def
setHeader
(header, value)
def
setOperation
(operation)
def
setRawHeader
(headerName, value)
def
setRequest
(request)
def
setSslConfiguration
(configuration)
def
setUrl
(url)
def
sslConfiguration
()
def
url
()
def
abort
()
def
ignoreSslErrors
()
def
ignoreSslErrorsImplementation
(arg__1)
def
setReadBufferSize
(size)
def
setSslConfigurationImplementation
(arg__1)
def
sslConfigurationImplementation
(arg__1)
def
downloadProgress
(bytesReceived, bytesTotal)
def
encrypted
()
def
error
(arg__1)
def
errorOccurred
(arg__1)
def
finished
()
def
metaDataChanged
()
def
preSharedKeyAuthenticationRequired
(authenticator)
def
redirectAllowed
()
def
redirected
(url)
def
sslErrors
(errors)
def
uploadProgress
(bytesSent, bytesTotal)
QNetworkReplyclass contains the data and meta data related to a request posted withQNetworkAccessManager。像QNetworkRequest, it contains a URL and headers (both in parsed and raw form), some information about the reply’s state and the contents of the reply itself.
QNetworkReplyis a sequential-accessQIODevice, which means that once data is read from the object, it no longer kept by the device. It is therefore the application’s responsibility to keep this data if it needs to. Whenever more data is received from the network and processed, thereadyRead()信号被发射。
downloadProgress()signal is also emitted when data is received, but the number of bytes contained in it may not represent the actual bytes received, if any transformation is done to the contents (for example, decompressing and removing the protocol overhead).Even though
QNetworkReply是QIODevice连接到回复内容,它还发射uploadProgress()signal, which indicates the progress of the upload for operations that have such content.注意
不要删除槽中对象,其已连接到
errorOccurred()orfinished()signal. UsedeleteLater().
QNetworkReply
(
[
parent=None
]
)
¶
- param parent
QObject
创建
QNetworkReply
object with parent
parent
.
You cannot directly instantiate
QNetworkReply
objects. Use
QNetworkAccessManager
函数以做到这。
PySide2.QtNetwork.QNetworkReply.
NetworkError
¶
指示在处理请求期间,发现的所有可能的错误条件。
|
常量 |
描述 |
|---|---|
|
QNetworkReply.NoError |
没有错误条件。 |
注意
当 HTTP 协议返回重定向时,不会报告错误。可以校验是否有重定向采用
RedirectionTargetAttribute
属性。
|
常量 |
描述 |
|---|---|
|
QNetworkReply.ConnectionRefusedError |
the remote server refused the connection (the server is not accepting requests) |
|
QNetworkReply.RemoteHostClosedError |
the remote server closed the connection prematurely, before the entire reply was received and processed |
|
QNetworkReply.HostNotFoundError |
the remote host name was not found (invalid hostname) |
|
QNetworkReply.TimeoutError |
the connection to the remote server timed out |
|
QNetworkReply.OperationCanceledError |
操作被取消经由调用
|
|
QNetworkReply.SslHandshakeFailedError |
the SSL/TLS handshake failed and the encrypted channel could not be established. The
|
|
QNetworkReply.TemporaryNetworkFailureError |
the connection was broken due to disconnection from the network, however the system has initiated roaming to another access point. The request should be resubmitted and will be processed as soon as the connection is re-established. |
|
QNetworkReply.NetworkSessionFailedError |
the connection was broken due to disconnection from the network or failure to start the network. |
|
QNetworkReply.BackgroundRequestNotAllowedError |
the background request is not currently allowed due to platform policy. |
|
QNetworkReply.TooManyRedirectsError |
while following redirects, the maximum limit was reached. The limit is by default set to 50 or as set by QNetworkRequest::setMaxRedirectsAllowed(). (This value was introduced in 5.6.) |
|
QNetworkReply.InsecureRedirectError |
while following redirects, the network access API detected a redirect from a encrypted protocol (https) to an unencrypted one (http). (This value was introduced in 5.6.) |
|
QNetworkReply.ProxyConnectionRefusedError |
the connection to the proxy server was refused (the proxy server is not accepting requests) |
|
QNetworkReply.ProxyConnectionClosedError |
the proxy server closed the connection prematurely, before the entire reply was received and processed |
|
QNetworkReply.ProxyNotFoundError |
the proxy host name was not found (invalid proxy hostname) |
|
QNetworkReply.ProxyTimeoutError |
the connection to the proxy timed out or the proxy did not reply in time to the request sent |
|
QNetworkReply.ProxyAuthenticationRequiredError |
the proxy requires authentication in order to honour the request but did not accept any credentials offered (if any) |
|
QNetworkReply.ContentAccessDenied |
the access to the remote content was denied (similar to HTTP error 403) |
|
QNetworkReply.ContentOperationNotPermittedError |
the operation requested on the remote content is not permitted |
|
QNetworkReply.ContentNotFoundError |
the remote content was not found at the server (similar to HTTP error 404) |
|
QNetworkReply.AuthenticationRequiredError |
the remote server requires authentication to serve the content but the credentials provided were not accepted (if any) |
|
QNetworkReply.ContentReSendError |
the request needed to be sent again, but this failed for example because the upload data could not be read a second time. |
|
QNetworkReply.ContentConflictError |
the request could not be completed due to a conflict with the current state of the resource. |
|
QNetworkReply.ContentGoneError |
the requested resource is no longer available at the server. |
|
QNetworkReply.InternalServerError |
the server encountered an unexpected condition which prevented it from fulfilling the request. |
|
QNetworkReply.OperationNotImplementedError |
the server does not support the functionality required to fulfill the request. |
|
QNetworkReply.ServiceUnavailableError |
服务器此时无法处理请求。 |
|
QNetworkReply.ProtocolUnknownError |
the Network Access API cannot honor the request because the protocol is not known |
|
QNetworkReply.ProtocolInvalidOperationError |
请求的操作对此协议无效 |
|
QNetworkReply.UnknownNetworkError |
an unknown network-related error was detected |
|
QNetworkReply.UnknownProxyError |
an unknown proxy-related error was detected |
|
QNetworkReply.UnknownContentError |
an unknown error related to the remote content was detected |
|
QNetworkReply.ProtocolFailure |
a breakdown in protocol was detected (parsing error, invalid or unexpected responses, etc.) |
|
QNetworkReply.UnknownServerError |
an unknown error related to the server response was detected |
另请参阅
PySide2.QtNetwork.QNetworkReply.
abort
(
)
¶
立即中止操作并关闭所有仍打开的网络连接。仍在进行中的上传也将被中止。
finished()
信号也会被发射。
另请参阅
close()
finished()
PySide2.QtNetwork.QNetworkReply.
attribute
(
code
)
¶
code
–
属性
object
返回的属性关联代码
code
。若尚未设置属性,则返回无效
QVariant
(类型
UnknownType
).
可以期望的默认值列表于
属性
以应用由此函数返回的值。
另请参阅
PySide2.QtNetwork.QNetworkReply.
downloadProgress
(
bytesReceived
,
bytesTotal
)
¶
bytesReceived
–
qint64
bytesTotal
–
qint64
PySide2.QtNetwork.QNetworkReply.
encrypted
(
)
¶
PySide2.QtNetwork.QNetworkReply.
error
(
)
¶
返回在此请求处理期间发现的错误。若未发现错误,返回
NoError
.
另请参阅
PySide2.QtNetwork.QNetworkReply.
error
(
arg__1
)
¶
arg__1
–
NetworkError
注意
此函数被弃用。
PySide2.QtNetwork.QNetworkReply.
errorOccurred
(
arg__1
)
¶
arg__1
–
NetworkError
PySide2.QtNetwork.QNetworkReply.
finished
(
)
¶
PySide2.QtNetwork.QNetworkReply.
hasRawHeader
(
headerName
)
¶
headerName
–
QByteArray
bool
返回
true
若原生 Header 头名
headerName
由远程服务器发送
另请参阅
PySide2.QtNetwork.QNetworkReply.
header
(
header
)
¶
header
–
KnownHeaders
object
返回值为已知头
header
,若 Header 头是由远程服务器发送的。若未发送头,则返回无效
QVariant
.
PySide2.QtNetwork.QNetworkReply.
ignoreSslErrors
(
)
¶
若此函数被调用,与网络连接相关的 SSL 错误将被忽略,包括证书验证错误。
警告
确保始终让用户审查报告的错误通过
sslErrors()
signal, and only call this method upon confirmation from the user that proceeding is ok. If there are unexpected errors, the reply should be aborted. Calling this method without inspecting the actual errors will most likely pose a security risk for your application. Use it with great care!
可以调用此函数从槽连接到
sslErrors()
signal, which indicates which errors were found.
注意
若 HSTS (HTTP 严格传输安全) 被启用对于
QNetworkAccessManager
,此函数不起作用。
PySide2.QtNetwork.QNetworkReply.
ignoreSslErrors
(
errors
)
¶
errors –
这是重载函数。
若此函数被调用,SSL 错误给出于
errors
将被忽略。
注意
由于大多数 SSL 错误关联证书,因此对于大多数证书而言,必须设置与此 SSL 错误相关的预期证书。例如,若想要向使用自签名证书的服务器发出请求,考虑以下片段:
QList<QSslCertificate> cert = QSslCertificate::fromPath(QLatin1String("server-certificate.pem"));
QSslError error(QSslError::SelfSignedCertificate, cert.at(0));
QList<QSslError> expectedSslErrors;
expectedSslErrors.append(error);
QNetworkReply *reply = manager.get(QNetworkRequest(QUrl("https://server.tld/index.html")));
reply->ignoreSslErrors(expectedSslErrors);
// here connect signals etc.
多次调用此函数将替换先前调用传入错误列表。可以清零想要忽略的错误列表通过采用空列表调用此函数。
注意
若 HSTS (HTTP 严格传输安全) 被启用对于
QNetworkAccessManager
,此函数不起作用。
PySide2.QtNetwork.QNetworkReply.
ignoreSslErrorsImplementation
(
arg__1
)
¶
arg__1 –
提供此虚拟方法以启用覆盖行为对
ignoreSslErrors()
.
ignoreSslErrors()
is a public wrapper for this method.
errors
包含用户希望忽略的错误。
另请参阅
PySide2.QtNetwork.QNetworkReply.
isFinished
(
)
¶
bool
返回
true
当回复已完成或被中止。
另请参阅
PySide2.QtNetwork.QNetworkReply.
isRunning
(
)
¶
bool
返回
true
当请求仍继续进行,且回复尚未完成或尚未被中止时。
另请参阅
PySide2.QtNetwork.QNetworkReply.
manager
(
)
¶
返回
QNetworkAccessManager
用于创建此
QNetworkReply
对象。最初,它还是父级对象。
PySide2.QtNetwork.QNetworkReply.
metaDataChanged
(
)
¶
PySide2.QtNetwork.QNetworkReply.
operation
(
)
¶
操作
返回此回复张贴的操作。
另请参阅
authenticator
–
QSslPreSharedKeyAuthenticator
PySide2.QtNetwork.QNetworkReply.
rawHeader
(
headerName
)
¶
headerName
–
QByteArray
QByteArray
返回原生内容,对于 Header
headerName
由远程服务器发送。若没有这种头,则返回空字节数组 (可能与空头难以区分)。使用
hasRawHeader()
to verify if the server sent such header field.
PySide2.QtNetwork.QNetworkReply.
rawHeaderList
(
)
¶
返回由远程服务器发送的 Header 字段列表,按发送顺序。重复 Header 被合并在一起并代替后者。
PySide2.QtNetwork.QNetworkReply.
rawHeaderPairs
(
)
¶
返回原生头对的列表。
PySide2.QtNetwork.QNetworkReply.
readBufferSize
(
)
¶
qint64
返回读取缓冲的尺寸 (以字节为单位)。
另请参阅
PySide2.QtNetwork.QNetworkReply.
redirectAllowed
(
)
¶
PySide2.QtNetwork.QNetworkReply.
redirected
(
url
)
¶
url
–
QUrl
PySide2.QtNetwork.QNetworkReply.
request
(
)
¶
返回此回复张贴的请求。特别注意:请求 URL 可能异于回复 URL。
另请参阅
PySide2.QtNetwork.QNetworkReply.
setAttribute
(
code
,
value
)
¶
code
–
属性
value – object
设置属性
code
到拥有值
value
。若
code
先前有设置,它将被覆盖。若
value
是无效
QVariant
,属性未设置。
PySide2.QtNetwork.QNetworkReply.
setError
(
errorCode
,
errorString
)
¶
errorCode
–
NetworkError
errorString – unicode
将错误条件设为
errorCode
。设置人类可读消息采用
errorString
.
Calling does not emit the
errorOccurred
(
NetworkError
) 信号。
另请参阅
error()
errorString()
PySide2.QtNetwork.QNetworkReply.
setFinished
(
arg__1
)
¶
arg__1
–
bool
把回复设置为
finished
.
在此设置之后,回复数据不得改变。
另请参阅
PySide2.QtNetwork.QNetworkReply.
setHeader
(
header
,
value
)
¶
header
–
KnownHeaders
value – object
设置已知头
header
到值
value
。相应原生格式的 Header 头也将被设置。
PySide2.QtNetwork.QNetworkReply.
setOperation
(
operation
)
¶
operation
–
操作
把此对象的关联操作设置为
operation
。该值会被返回,通过
operation()
.
注意
应在创建此对象,且不再更改时设置该操作。
另请参阅
PySide2.QtNetwork.QNetworkReply.
setRawHeader
(
headerName
,
value
)
¶
headerName
–
QByteArray
value
–
QByteArray
设置原生头
headerName
到值
value
。若
headerName
先前有设置,则会被覆盖。相同名称的多个 HTTP 头在功能上相当于值串联的某一单头,以逗号分隔。
若
headerName
匹配已知 Header 头,值
value
将被剖析且还将设置相应剖析形式。
PySide2.QtNetwork.QNetworkReply.
setReadBufferSize
(
size
)
¶
size
–
qint64
将读取缓冲的大小设为
size
字节。读取缓冲是保持网络下载数据的缓冲,在读取采用
read()
. Setting the buffer size to 0 will make the buffer unlimited in size.
QNetworkReply
将试着停止从网络读取,一旦此缓冲已满 (即,
bytesAvailable()
返回
size
或更多),因此还会导致下载速度下降。若缓冲大小不受限制,
QNetworkReply
将试着从网络尽可能快下载。
不像
setReadBufferSize()
,
QNetworkReply
无法保证读取缓冲大小的精度。即,
bytesAvailable()
can return more than
size
.
另请参阅
PySide2.QtNetwork.QNetworkReply.
setRequest
(
request
)
¶
request
–
QNetworkRequest
将此对象的关联请求设为
request
。该值会被返回,通过
request()
.
注意
应设置请求,当创建此对象时,且不要再次改变。
另请参阅
PySide2.QtNetwork.QNetworkReply.
setSslConfiguration
(
configuration
)
¶
configuration
–
QSslConfiguration
若可能的话,将此请求关联的网络连接的 SSL 配置设为
config
.
另请参阅
PySide2.QtNetwork.QNetworkReply.
setSslConfigurationImplementation
(
arg__1
)
¶
arg__1
–
QSslConfiguration
提供此虚拟方法以启用覆盖行为对
setSslConfiguration()
.
setSslConfiguration()
is a public wrapper for this method. If you override this method use
configuration
去设置 SSL 配置。
PySide2.QtNetwork.QNetworkReply.
setUrl
(
url
)
¶
url
–
QUrl
将正在处理的 URL 设为
url
。通常,URL 匹配请求所张贴的 URL,但由于多种原因可能有所不同 (例如:将文件路径变为绝对路径或典型路径)。
PySide2.QtNetwork.QNetworkReply.
sslConfiguration
(
)
¶
Returns the SSL configuration and state associated with this reply, if SSL was used. It will contain the remote server’s certificate, its certificate chain leading to the Certificate Authority as well as the encryption ciphers in use.
The peer’s certificate and its certificate chain will be known by the time
sslErrors()
is emitted, if it’s emitted.
PySide2.QtNetwork.QNetworkReply.
sslConfigurationImplementation
(
arg__1
)
¶
arg__1
–
QSslConfiguration
提供此虚拟方法以启用覆盖行为对
sslConfiguration()
.
sslConfiguration()
is a public wrapper for this method. The configuration will be returned in
configuration
.
PySide2.QtNetwork.QNetworkReply.
sslErrors
(
errors
)
¶
errors –
PySide2.QtNetwork.QNetworkReply.
uploadProgress
(
bytesSent
,
bytesTotal
)
¶
bytesSent
–
qint64
bytesTotal
–
qint64
PySide2.QtNetwork.QNetworkReply.
url
(
)
¶
QUrl
返回下载或上传内容的 URL。注意,URL 可能异于原始请求 URL。若
FollowRedirectsAttribute
是在请求中设置的,则此函数返回网络 API 正在访问的当前网址,即发射 URL 在
redirected
信号。