QHttpServerResponse Class

Encapsulates an HTTP response. 更多...

头: #include <QHttpServerResponse>
CMake: find_package(Qt6 REQUIRED COMPONENTS HttpServer)
target_link_libraries(mytarget PRIVATE Qt6::HttpServer)
qmake: QT += httpserver
Since: Qt 6.4

公共类型

StatusCode

公共函数

QHttpServerResponse (QHttpServerResponse::StatusCode statusCode )
QHttpServerResponse (QByteArray && data , QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse (const QByteArray & data , QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse (const QJsonArray & data , QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse (const QJsonObject & data , QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse (const QString & data , QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse (const char * data , QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse (const QByteArray & mimeType , QByteArray && data , QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse (const QByteArray & mimeType , const QByteArray & data , QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse (QHttpServerResponse && other )
~QHttpServerResponse ()
QByteArray data () const
(从 6.8 起) QHttpHeaders headers () const
QByteArray mimeType () const
(从 6.8 起) void setHeaders (QHttpHeaders && newHeaders )
(从 6.8 起) void setHeaders (const QHttpHeaders & newHeaders )
QHttpServerResponse::StatusCode statusCode () const
void swap (QHttpServerResponse & other )
QHttpServerResponse & operator= (QHttpServerResponse && other )

静态公共成员

QHttpServerResponse fromFile (const QString & fileName )

详细描述

API for creating, reading and modifying a response from an HTTP server, and for writing its contents to a QHttpServerResponder . It has numerous constructors, and static function fromFile for constructing it from the contents of a file. There are functions for setting, getting, and removing headers, and for getting the data, status code and mime type.

成员类型文档编制

[alias] QHttpServerResponse:: StatusCode

Type alias for QHttpServerResponder::StatusCode

成员函数文档编制

QHttpServerResponse:: QHttpServerResponse (const QByteArray & mimeType , QByteArray && data , QHttpServerResponse::StatusCode status = StatusCode::Ok)

QHttpServerResponse:: QHttpServerResponse (const QByteArray & mimeType , const QByteArray & data , QHttpServerResponse::StatusCode status = StatusCode::Ok)

创建 QHttpServer response.

The response will use the given status code and deliver the data as its body, with a ContentType header describing it as being of MIME type mimeType .

QHttpServerResponse:: QHttpServerResponse ( QHttpServerResponse::StatusCode statusCode )

Creates a QHttpServerResponse object with the status code statusCode .

QHttpServerResponse:: QHttpServerResponse ( QByteArray && data , QHttpServerResponse::StatusCode status = StatusCode::Ok)

Move-constructs a QHttpServerResponse whose body will contain the given data with the status code status .

QHttpServerResponse:: QHttpServerResponse (const QByteArray & data , QHttpServerResponse::StatusCode status = StatusCode::Ok)

Creates a QHttpServerResponse object from data with the status code status .

QHttpServerResponse:: QHttpServerResponse (const QJsonArray & data , QHttpServerResponse::StatusCode status = StatusCode::Ok)

Creates a QHttpServerResponse object from data with the status code status .

QHttpServerResponse:: QHttpServerResponse (const QJsonObject & data , QHttpServerResponse::StatusCode status = StatusCode::Ok)

Creates a QHttpServerResponse object from data with the status code status .

QHttpServerResponse:: QHttpServerResponse (const QString & data , QHttpServerResponse::StatusCode status = StatusCode::Ok)

Creates a QHttpServerResponse object from data with the status code status .

QHttpServerResponse:: QHttpServerResponse (const char * data , QHttpServerResponse::StatusCode status = StatusCode::Ok)

Creates a QHttpServerResponse object from data with the status code status .

[noexcept] QHttpServerResponse:: QHttpServerResponse ( QHttpServerResponse && other )

Move-constructs a new QHttpServerResponse from other .

[noexcept] QHttpServerResponse:: ~QHttpServerResponse ()

销毁 QHttpServerResponse 对象。

QByteArray QHttpServerResponse:: data () const

Returns the response body.

[static] QHttpServerResponse QHttpServerResponse:: fromFile (const QString & fileName )

返回 QHttpServerResponse from the content of the file fileName .

It is the caller's responsibility to sanity-check the filename, and to have a well-defined policy for which files the server will request.

[since 6.8] QHttpHeaders QHttpServerResponse:: headers () const

Returns the currently set HTTP headers.

该函数在 Qt 6.8 引入。

另请参阅 setHeaders ().

QByteArray QHttpServerResponse:: mimeType () const

Returns the value of the HTTP "Content-Type" header.

注意: Default value is "text/html"

[since 6.8] void QHttpServerResponse:: setHeaders ( QHttpHeaders && newHeaders )

设置 newHeaders as the HTTP headers, overriding any previously set headers.

该函数在 Qt 6.8 引入。

另请参阅 headers ().

[since 6.8] void QHttpServerResponse:: setHeaders (const QHttpHeaders & newHeaders )

这是重载函数。

该函数在 Qt 6.8 引入。

QHttpServerResponse::StatusCode QHttpServerResponse:: statusCode () const

Returns the status code.

[noexcept] void QHttpServerResponse:: swap ( QHttpServerResponse & other )

交换此 QHttpServerResponse with other 。此操作非常快且从不失败。

[noexcept] QHttpServerResponse &QHttpServerResponse:: operator= ( QHttpServerResponse && other )

移动赋值 other 到此 QHttpServerResponse 实例。