本页内容

QHttpServerRequest Class

封装了一个 HTTP 请求。更多...

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

公共类型

enum class Method { Unknown, Get, Put, Delete, Post, …, AnyKnown }
flags Methods

公共函数

(since 6.10) QHttpServerRequest()
(since 6.10) QHttpServerRequest(const QHttpServerRequest &other)
(since 6.10) QHttpServerRequest(QHttpServerRequest &&other)
~QHttpServerRequest()
QByteArray body() const
QHttpHeaders headers() &&
const QHttpHeaders &headers() const &
(since 6.5) QHostAddress localAddress() const
(since 6.5) quint16 localPort() const
QHttpServerRequest::Method method() const
QUrlQuery query() const
QHostAddress remoteAddress() const
(since 6.5) quint16 remotePort() const
(since 6.7) QSslConfiguration sslConfiguration() const
(since 6.10) void swap(QHttpServerRequest &other)
QUrl url() const
QByteArray value(const QByteArray &key) const
(since 6.10) QHttpServerRequest &operator=(QHttpServerRequest &&other)
(since 6.10) QHttpServerRequest &operator=(const QHttpServerRequest &other)
QDebug operator<<(QDebug debug, const QHttpServerRequest &request)

详细说明

用于访问传入请求中不同参数的 API。

成员类型文档

enum class QHttpServerRequest::Method
flags QHttpServerRequest::Methods

此枚举类型用于指定 HTTP 请求方法:

常量值描述
QHttpServerRequest::Method::Unknown0x0000未知的方法。
QHttpServerRequest::Method::Get0x0001HTTP GET 方法。
QHttpServerRequest::Method::Put0x0002HTTP PUT 方法。
QHttpServerRequest::Method::Delete0x0004HTTP DELETE 方法。
QHttpServerRequest::Method::Post0x0008HTTP POST 方法。
QHttpServerRequest::Method::Head0x0010HTTP HEAD 方法。
QHttpServerRequest::Method::Options0x0020HTTP OPTIONS 方法。
QHttpServerRequest::Method::Patch0x0040HTTP PATCH 方法(RFC 5789)。
QHttpServerRequest::Method::Connect0x0080HTTP CONNECT 方法。
QHttpServerRequest::Method::Trace0x0100HTTP TRACE 方法。
QHttpServerRequest::Method::AnyKnownGet | Put | Delete | Post | Head | Options | Patch | Connect | Trace所有已知方法的组合。

Methods 类型是QFlags<Method> 的 typedef。它存储 Method 值的或(OR)组合。

成员函数文档

[since 6.10] QHttpServerRequest::QHttpServerRequest()

创建一个 QHttpServerRequest 对象。

该函数在 Qt 6.10 中引入。

[since 6.10] QHttpServerRequest::QHttpServerRequest(const QHttpServerRequest &other)

Copy 使用 `other` 构建一个 `QHttpServerRequest`。

该函数在 Qt 6.10 中引入。

[constexpr noexcept default, since 6.10] QHttpServerRequest::QHttpServerRequest(QHttpServerRequest &&other)

该函数使用 `other` 构造一个 `QHttpServerRequest` 对象。

该函数在 Qt 6.10 中引入。

[noexcept] QHttpServerRequest::~QHttpServerRequest()

摧毁一个QHttpServerRequest

QByteArray QHttpServerRequest::body() const

返回请求正文。

QHttpHeaders QHttpServerRequest::headers() &&

const QHttpHeaders &QHttpServerRequest::headers() const &

返回所有请求头。

[since 6.5] QHostAddress QHttpServerRequest::localAddress() const

返回接收该请求的本地套接字的主机地址。

该函数于 Qt 6.5 中引入。

[since 6.5] quint16 QHttpServerRequest::localPort() const

返回接收该请求的本地套接字的端口号。

该函数于 Qt 6.5 中引入。

QHttpServerRequest::Method QHttpServerRequest::method() const

返回请求的方法。

QUrlQuery QHttpServerRequest::query() const

返回请求中的查询。

QHostAddress QHttpServerRequest::remoteAddress() const

返回请求源主机的地址。

[since 6.5] quint16 QHttpServerRequest::remotePort() const

返回请求源主机的端口号。

该函数于 Qt 6.5 中引入。

[since 6.7] QSslConfiguration QHttpServerRequest::sslConfiguration() const

返回已建立的 TLS 连接的配置。如果连接未使用 TLS,则这些配置在调用 isNull() 时将返回 true。

该函数于 Qt 6.7 中引入。

[noexcept, since 6.10] void QHttpServerRequest::swap(QHttpServerRequest &other)

交换此处与 `other` 之间的值。

该函数于 Qt 6.10 中引入。

QUrl QHttpServerRequest::url() const

返回请求中指定的 URL。

QByteArray QHttpServerRequest::value(const QByteArray &key) const

返回所有名称为key 的标头的合并值。

[noexcept, since 6.10] QHttpServerRequest &QHttpServerRequest::operator=(QHttpServerRequest &&other)

`Move` 通过 `other` 分配一个 `QHttpServerRequest `。

该函数在 Qt 6.10 中引入。

[since 6.10] QHttpServerRequest &QHttpServerRequest::operator=(const QHttpServerRequest &other)

使用 `other` 分配一个 `QHttpServerRequest `。

该函数在 Qt 6.10 中引入。

相关的非成员函数

QDebug operator<<(QDebug debug, const QHttpServerRequest &request)

将request 的相关信息写入debug 流。

另请参阅 QDebug 。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.