PySide6.QtHttpServer.QHttpServerResponder

class QHttpServerResponder

用于从HTTP服务器发送回复的API。更多

概要

方法

注意

本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。

详细描述

提供用于将数据写回HTTP客户端的函数,包括序列化JSON对象的重载。它还支持写入HTTP头和状态码。

class StatusCode

HTTP状态码

常量

描述

QHttpServerResponder.StatusCode.Continue

QHttpServerResponder.StatusCode.SwitchingProtocols

QHttpServerResponder.StatusCode.Processing

QHttpServerResponder.StatusCode.Ok

QHttpServerResponder.StatusCode.Created

QHttpServerResponder.StatusCode.Accepted

QHttpServerResponder.StatusCode.NonAuthoritativeInformation

QHttpServerResponder.StatusCode.NoContent

QHttpServerResponder.StatusCode.ResetContent

QHttpServerResponder.StatusCode.PartialContent

QHttpServerResponder.StatusCode.MultiStatus

QHttpServerResponder.StatusCode.AlreadyReported

QHttpServerResponder.StatusCode.IMUsed

QHttpServerResponder.StatusCode.MultipleChoices

QHttpServerResponder.StatusCode.MovedPermanently

QHttpServerResponder.StatusCode.Found

QHttpServerResponder.StatusCode.SeeOther

QHttpServerResponder.StatusCode.NotModified

QHttpServerResponder.StatusCode.UseProxy

QHttpServerResponder.StatusCode.TemporaryRedirect

QHttpServerResponder.StatusCode.PermanentRedirect

QHttpServerResponder.StatusCode.BadRequest

QHttpServerResponder.StatusCode.Unauthorized

QHttpServerResponder.StatusCode.PaymentRequired

QHttpServerResponder.StatusCode.Forbidden

QHttpServerResponder.StatusCode.NotFound

QHttpServerResponder.StatusCode.MethodNotAllowed

QHttpServerResponder.StatusCode.NotAcceptable

QHttpServerResponder.StatusCode.ProxyAuthenticationRequired

QHttpServerResponder.StatusCode.RequestTimeout

QHttpServerResponder.StatusCode.Conflict

QHttpServerResponder.StatusCode.Gone

QHttpServerResponder.StatusCode.LengthRequired

QHttpServerResponder.StatusCode.PreconditionFailed

QHttpServerResponder.StatusCode.PayloadTooLarge

QHttpServerResponder.StatusCode.UriTooLong

QHttpServerResponder.StatusCode.UnsupportedMediaType

QHttpServerResponder.StatusCode.RequestRangeNotSatisfiable

QHttpServerResponder.StatusCode.ExpectationFailed

QHttpServerResponder.StatusCode.ImATeapot

QHttpServerResponder.StatusCode.MisdirectedRequest

QHttpServerResponder.StatusCode.UnprocessableEntity

QHttpServerResponder.StatusCode.Locked

QHttpServerResponder.StatusCode.FailedDependency

QHttpServerResponder.StatusCode.UpgradeRequired

QHttpServerResponder.StatusCode.PreconditionRequired

QHttpServerResponder.StatusCode.TooManyRequests

QHttpServerResponder.StatusCode.RequestHeaderFieldsTooLarge

QHttpServerResponder.StatusCode.UnavailableForLegalReasons

QHttpServerResponder.StatusCode.InternalServerError

QHttpServerResponder.StatusCode.NotImplemented

QHttpServerResponder.StatusCode.BadGateway

QHttpServerResponder.StatusCode.ServiceUnavailable

QHttpServerResponder.StatusCode.GatewayTimeout

QHttpServerResponder.StatusCode.HttpVersionNotSupported

QHttpServerResponder.StatusCode.VariantAlsoNegotiates

QHttpServerResponder.StatusCode.InsufficientStorage

QHttpServerResponder.StatusCode.LoopDetected

QHttpServerResponder.StatusCode.NotExtended

QHttpServerResponder.StatusCode.NetworkAuthenticationRequired

QHttpServerResponder.StatusCode.NetworkConnectTimeoutError

sendResponse(response)
Parameters:

响应QHttpServerResponse

向客户端发送一个HTTP response

swap(other)
Parameters:

其他QHttpServerResponder

QHttpServerResponder other与此QHttpServerResponder交换。此操作非常快速且永远不会失败。

write([status=QHttpServerResponder.StatusCode.Ok])
Parameters:

状态StatusCode

使用HTTP状态代码status回答请求。

注意:此函数将HTTP Content-Type标头设置为“application/x-empty”。

write(headers[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

使用HTTP状态码status和HTTP头headers来响应请求。

write(document[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

使用HTTP状态码status和JSON文档document来响应请求。

注意:此函数将HTTP Content-Type标头设置为“application/json”。

write(data, mimeType[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

使用HTTP状态码status和MIME类型mimeType来响应请求。I/O设备data提供响应的主体。如果data是顺序的,消息的主体将分块发送:否则,函数假定所有内容都可用并一次性发送,但读取是分块进行的。

注意

此函数获取data的所有权。

write(data, headers[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

使用HTTP状态码status和HTTP头headers来响应请求。I/O设备data提供响应的主体。如果data是顺序的,消息的主体将分块发送:否则,函数假定所有内容都可用并一次性发送,但读取是分块进行的。

注意

此函数获取data的所有权。

write(data, mimeType[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

使用HTTP状态码status、MIME类型mimeType和主体data来响应请求。

write(data, headers[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

使用HTTP状态码status、HTTP头headers和主体data来响应请求。

注意:此函数设置HTTP Content-Length头。

write(document, headers[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

使用HTTP状态码status、JSON文档document和HTTP头headers来响应请求。

注意:此函数将HTTP Content-Type标头设置为“application/json”。

writeBeginChunked(mimeType[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

开始发送具有MIME类型mimeType和给定状态码status的数据块。此调用之后必须跟随任意数量的重复writeChunk调用和一次writeEndChunked调用。

writeBeginChunked(headers[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

开始发送带有headers和状态码status的数据块。此调用之后必须跟随任意数量的重复writeChunk调用和一次writeEndChunked调用。

writeBeginChunked(headers, trailerNames[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

开始发送带有headers的数据块和给定的状态码status。此调用必须后跟任意数量的重复writeChunk调用,并且必须使用trailers中给出的相同尾部进行单次调用writeEndChunked

writeChunk(data)
Parameters:

数据QByteArray

data写回客户端。当有数据可写时调用。可以多次调用,但在调用此函数之前必须调用writeBeginChunked,之后必须调用writeEndChunked

writeEndChunked(data)
Parameters:

数据QByteArray

data写回客户端。必须在调用writeBeginChunked之后进行。

writeEndChunked(data, trailers)
Parameters:

使用writeBeginChunked中声明的trailersdata写回客户端。