QNetworkReply

概要

函数

虚函数

信号

详细描述

PySide.QtNetwork.QNetworkReply class contains the data and headers for a request sent with PySide.QtNetwork.QNetworkAccessManager

PySide.QtNetwork.QNetworkReply class contains the data and meta data related to a request posted with PySide.QtNetwork.QNetworkAccessManager 。像 PySide.QtNetwork.QNetworkRequest ,它包含 URL 和 Header (两者的剖析和原生表单),有关回复状态的一些信息及回复本身的内容。

PySide.QtNetwork.QNetworkReply is a sequential-access PySide.QtCore.QIODevice ,意味着一旦从对象读取数据,数据就不再由设备所保持。因此,应用程序有责任保持此数据,若需要的话。每当从网络接收和处理更多数据时, PySide.QtCore.QIODevice.readyRead() 信号被发射。

PySide.QtNetwork.QNetworkReply.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 PySide.QtNetwork.QNetworkReply PySide.QtCore.QIODevice 连接到回复内容,它还发射 PySide.QtNetwork.QNetworkReply.uploadProgress() signal, which indicates the progress of the upload for operations that have such content.

注意

不要删除槽中对象,其已连接到 PySide.QtNetwork.QNetworkReply.error() or PySide.QtNetwork.QNetworkReply.finished() signal. Use PySide.QtCore.QObject.deleteLater() .

class PySide.QtNetwork. QNetworkReply ( [ parent=None ] )
参数: parent PySide.QtCore.QObject

创建 PySide.QtNetwork.QNetworkReply object with parent parent .

You cannot directly instantiate PySide.QtNetwork.QNetworkReply objects. Use PySide.QtNetwork.QNetworkAccessManager 函数以做到这。

PySide.QtNetwork.QNetworkReply. NetworkError

指示在处理请求期间,发现的所有可能的错误条件。

常量 描述
QNetworkReply.NoError 没有错误条件。 注意: 当 HTTP 协议返回重定向时,不会报告错误。可以校验是否有重定向采用 QNetworkRequest.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 操作被取消经由调用 PySide.QtNetwork.QNetworkReply.abort() or PySide.QtNetwork.QNetworkReply.close() before it was finished.
QNetworkReply.SslHandshakeFailedError the SSL/TLS handshake failed and the encrypted channel could not be established. The PySide.QtNetwork.QNetworkReply.sslErrors() signal should have been emitted.
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.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 401)
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.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.)
PySide.QtNetwork.QNetworkReply. abort ( )

立即中止操作并关闭所有仍打开的网络连接。仍在进行中的上传也将被中止。

另请参阅

PySide.QtNetwork.QNetworkReply.close()

PySide.QtNetwork.QNetworkReply. attribute ( code )
参数: code PySide.QtNetwork.QNetworkRequest.Attribute
返回类型: object
PySide.QtNetwork.QNetworkReply. downloadProgress ( bytesReceived , bytesTotal )
参数:
  • bytesReceived PySide.QtCore.qint64
  • bytesTotal PySide.QtCore.qint64
PySide.QtNetwork.QNetworkReply. error ( )
返回类型: PySide.QtNetwork.QNetworkReply.NetworkError

返回在此请求处理期间发现的错误。若未发现错误,返回 NoError .

PySide.QtNetwork.QNetworkReply. error ( arg__1 )
参数: arg__1 PySide.QtNetwork.QNetworkReply.NetworkError
PySide.QtNetwork.QNetworkReply. finished ( )
PySide.QtNetwork.QNetworkReply. hasRawHeader ( headerName )
参数: headerName PySide.QtCore.QByteArray
返回类型: PySide.QtCore.bool

Returns true if the raw header of name headerName 由远程服务器发送

PySide.QtNetwork.QNetworkReply. header ( header )
参数: header PySide.QtNetwork.QNetworkRequest.KnownHeaders
返回类型: object
PySide.QtNetwork.QNetworkReply. ignoreSslErrors ( )

若此函数被调用,与网络连接相关的 SSL 错误将被忽略,包括证书验证错误。

警告

确保始终让用户审查报告的错误通过 PySide.QtNetwork.QNetworkReply.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!

可以调用此函数从槽连接到 PySide.QtNetwork.QNetworkReply.sslErrors() signal, which indicates which errors were found.

PySide.QtNetwork.QNetworkReply. ignoreSslErrors ( errors )
参数: errors
PySide.QtNetwork.QNetworkReply. isFinished ( )
返回类型: PySide.QtCore.bool

Returns true when the reply has finished or was aborted.

PySide.QtNetwork.QNetworkReply. isRunning ( )
返回类型: PySide.QtCore.bool

Returns true when the request is still processing and the reply has not finished or was aborted yet.

PySide.QtNetwork.QNetworkReply. manager ( )
返回类型: PySide.QtNetwork.QNetworkAccessManager

返回 PySide.QtNetwork.QNetworkAccessManager 用于创建此 PySide.QtNetwork.QNetworkReply 对象。最初,它还是父级对象。

PySide.QtNetwork.QNetworkReply. metaDataChanged ( )
PySide.QtNetwork.QNetworkReply. operation ( )
返回类型: PySide.QtNetwork.QNetworkAccessManager.Operation

返回此回复张贴的操作。

PySide.QtNetwork.QNetworkReply. rawHeader ( headerName )
参数: headerName PySide.QtCore.QByteArray
返回类型: PySide.QtCore.QByteArray

返回原生内容,对于 Header headerName 由远程服务器发送。若没有这种头,则返回空字节数组 (可能与空头难以区分)。使用 PySide.QtNetwork.QNetworkReply.hasRawHeader() to verify if the server sent such header field.

PySide.QtNetwork.QNetworkReply. rawHeaderList ( )
返回类型:

返回由远程服务器发送的 Header 字段列表,按发送顺序。重复 Header 被合并在一起并代替后者。

PySide.QtNetwork.QNetworkReply. rawHeaderPairs ( )
返回类型:

返回原生头对的列表。

PySide.QtNetwork.QNetworkReply. readBufferSize ( )
返回类型: PySide.QtCore.qint64

返回读取缓冲的尺寸 (以字节为单位)。

PySide.QtNetwork.QNetworkReply. request ( )
返回类型: PySide.QtNetwork.QNetworkRequest

返回此回复张贴的请求。特别注意:请求 URL 可能异于回复 URL。

PySide.QtNetwork.QNetworkReply. setAttribute ( code , value )
参数:
PySide.QtNetwork.QNetworkReply. setError ( errorCode , errorString )
参数:

将错误条件设为 errorCode 。设置人类可读消息采用 errorString .

调用 PySide.QtNetwork.QNetworkReply.setError() does not emit the error( QNetworkReply.NetworkError ) 信号。

另请参阅

PySide.QtNetwork.QNetworkReply.error() PySide.QtCore.QIODevice.errorString()

PySide.QtNetwork.QNetworkReply. setFinished ( arg__1 )
参数: arg__1 PySide.QtCore.bool

把回复设置为 finished .

在此设置之后,回复数据不得改变。

PySide.QtNetwork.QNetworkReply. setHeader ( header , value )
参数:
PySide.QtNetwork.QNetworkReply. setOperation ( operation )
参数: operation PySide.QtNetwork.QNetworkAccessManager.Operation
PySide.QtNetwork.QNetworkReply. setRawHeader ( headerName , value )
参数:

设置原生头 headerName 到值 value 。若 headerName 先前有设置,则会被覆盖。相同名称的多个 HTTP 头在功能上相当于值串联的某一单头,以逗号分隔。

headerName 匹配已知 Header 头,值 value 将被剖析且还将设置相应剖析形式。

PySide.QtNetwork.QNetworkReply. setReadBufferSize ( size )
参数: size PySide.QtCore.qint64

将读取缓冲的大小设为 size 字节。读取缓冲是保持网络下载数据的缓冲,在读取采用 QIODevice.read() . Setting the buffer size to 0 will make the buffer unlimited in size.

PySide.QtNetwork.QNetworkReply 将试着停止从网络读取,一旦此缓冲已满 (即, PySide.QtCore.QIODevice.bytesAvailable() 返回 size 或更多),因此还会导致下载速度下降。若缓冲大小不受限制, PySide.QtNetwork.QNetworkReply 将试着从网络尽可能快下载。

不像 QAbstractSocket.setReadBufferSize() , PySide.QtNetwork.QNetworkReply 无法保证读取缓冲大小的精度。即, PySide.QtCore.QIODevice.bytesAvailable() can return more than size .

PySide.QtNetwork.QNetworkReply. setRequest ( request )
参数: request PySide.QtNetwork.QNetworkRequest

将此对象的关联请求设为 request 。该值会被返回,通过 PySide.QtNetwork.QNetworkReply.request() .

Note: the request should be set when this object is created and not changed again.

PySide.QtNetwork.QNetworkReply. setSslConfiguration ( configuration )
参数: configuration PySide.QtNetwork.QSslConfiguration

若可能的话,将此请求关联的网络连接的 SSL 配置设为 config .

PySide.QtNetwork.QNetworkReply. setUrl ( url )
参数: url PySide.QtCore.QUrl

将正在处理的 URL 设为 url 。通常,URL 匹配请求所张贴的 URL,但由于多种原因可能有所不同 (例如:将文件路径变为绝对路径或典型路径)。

PySide.QtNetwork.QNetworkReply. sslConfiguration ( )
返回类型: PySide.QtNetwork.QSslConfiguration

返回此回复关联的 SSL 配置和状态,若有使用 SSL。它将包含远程服务器证书、通向证书颁发机构的证书链及在使用中的加密密码。

对等方的证书及其证书链将是已知的,当 PySide.QtNetwork.QNetworkReply.sslErrors() is emitted, if it's emitted.

PySide.QtNetwork.QNetworkReply. sslErrors ( errors )
参数: errors
PySide.QtNetwork.QNetworkReply. uploadProgress ( bytesSent , bytesTotal )
参数:
  • bytesSent PySide.QtCore.qint64
  • bytesTotal PySide.QtCore.qint64
PySide.QtNetwork.QNetworkReply. url ( )
返回类型: PySide.QtCore.QUrl

Returns the URL of the content downloaded or uploaded. Note that the URL may be different from that of the original request.