QWebEngineHttpRequest Class
QWebEngineHttpRequest 类包含一个要通过WebEngine 发送的请求。更多
头文件: | #include <QWebEngineHttpRequest> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS WebEngineCore) target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore) |
qmake: | QT += webenginecore |
公共类型
enum | Method { Get, Post } |
公共函数
QWebEngineHttpRequest(const QUrl &url = QUrl(), const QWebEngineHttpRequest::Method &method = QWebEngineHttpRequest::Get) | |
QWebEngineHttpRequest(const QWebEngineHttpRequest &other) | |
~QWebEngineHttpRequest() | |
bool | hasHeader(const QByteArray &headerName) const |
QByteArray | header(const QByteArray &headerName) const |
QList<QByteArray> | headers() const |
QWebEngineHttpRequest::Method | method() const |
QByteArray | postData() const |
void | setHeader(const QByteArray &headerName, const QByteArray &headerValue) |
void | setMethod(QWebEngineHttpRequest::Method method) |
void | setPostData(const QByteArray &postData) |
void | setUrl(const QUrl &url) |
void | swap(QWebEngineHttpRequest &other) |
void | unsetHeader(const QByteArray &key) |
QUrl | url() const |
bool | operator!=(const QWebEngineHttpRequest &other) const |
QWebEngineHttpRequest & | operator=(const QWebEngineHttpRequest &other) |
bool | operator==(const QWebEngineHttpRequest &other) const |
静态公共成员
QWebEngineHttpRequest | postRequest(const QUrl &url, const QMap<QString, QString> &postData) |
详细说明
QWebEngineHttpRequest 表示WebEngine 网络协议栈中的 HTTP 请求。它包含通过网络发送请求所需的信息。它包含一个 URL 和一些可用于修改请求的辅助信息。QWebEnginePage::load() 和QWebEngineView::load() 都接受 QWebEngineHttpRequest 作为参数。
成员类型文档
enum QWebEngineHttpRequest::Method
该枚举类型描述用于发送 HTTP 请求的方法:
常量 | 值 | 描述 |
---|---|---|
QWebEngineHttpRequest::Get | 0 | GET 方法。 |
QWebEngineHttpRequest::Post | 1 | POST 方法 |
成员函数文档
[explicit]
QWebEngineHttpRequest::QWebEngineHttpRequest(const QUrl &url = QUrl(), const QWebEngineHttpRequest::Method &method = QWebEngineHttpRequest::Get)
构造一个 QWebEngineHttpRequest 对象,其中url 是要请求的 URL,method 是要使用的方法。
QWebEngineHttpRequest::QWebEngineHttpRequest(const QWebEngineHttpRequest &other)
创建other 的副本。
[noexcept]
QWebEngineHttpRequest::~QWebEngineHttpRequest()
处理QWebEngineHttpRequest 对象。
bool QWebEngineHttpRequest::hasHeader(const QByteArray &headerName) const
如果WebEngine 请求中存在headerName 头信息,则返回true
。
另请参阅 setHeader()、header()、unsetHeader() 和headers()。
QByteArray QWebEngineHttpRequest::header(const QByteArray &headerName) const
返回headerName 指定的标头。如果不存在这样的标头,则返回空QByteArray ,这可能与存在但没有内容的标头无异(使用hasHeader() 查找标头是否存在)。
可以使用setHeader() 设置头。
另请参见 setHeader()、hasHeader()、unsetHeader() 和headers()。
QList<QByteArray> QWebEngineHttpRequest::headers() const
返回WebEngine 请求中设置的所有标头的列表。该列表以设置标头的顺序排列。
另请参阅 setHeader()、header()、hasHeader() 和unsetHeader()。
QWebEngineHttpRequest::Method QWebEngineHttpRequest::method() const
返回WebEngine 请求使用的方法。
另请参阅 setMethod()。
QByteArray QWebEngineHttpRequest::postData() const
返回WebEngine 请求包含的(原始)POST 数据。
另请参见 setPostData().
[static]
QWebEngineHttpRequest QWebEngineHttpRequest::postRequest(const QUrl &url, const QMap<QString, QString> &postData)
构造一个使用 POST 方法指向url 的QWebEngineHttpRequest 。
注: postData 可包含任意字符串。它们会被转换为适当的原始数据。
另请参阅 postData 和setPostData()。
void QWebEngineHttpRequest::setHeader(const QByteArray &headerName, const QByteArray &headerValue)
将标题headerName 设置为headerValue 。
注意: 两次设置同一标头会覆盖前一次设置。要实现多个同名 HTTP 头信息的行为,应将两个值连接起来,用逗号(",")分隔,然后设置一个单一的头信息。
另请参见 header()、hasHeader()、unsetHeader() 和headers()。
void QWebEngineHttpRequest::setMethod(QWebEngineHttpRequest::Method method)
将WebEngine 请求使用的方法设置为method 。
另请参阅 method() 。
void QWebEngineHttpRequest::setPostData(const QByteArray &postData)
将WebEngine 请求包含的(原始)POST 数据设置为postData 。
另请参阅 postData() 。
void QWebEngineHttpRequest::setUrl(const QUrl &url)
将WebEngine 请求指向的 URL 设置为url 。
另请参阅 url() 。
[noexcept]
void QWebEngineHttpRequest::swap(QWebEngineHttpRequest &other)
将WebEngine 请求与other 互换。该功能运行速度非常快,从未出现过故障。
void QWebEngineHttpRequest::unsetHeader(const QByteArray &key)
删除key 指定的头信息(如果存在)。
另请参阅 setHeader()、header()、hasHeader() 和headers() 。
QUrl QWebEngineHttpRequest::url() const
返回WebEngine 请求指向的 URL。
另请参阅 setUrl().
bool QWebEngineHttpRequest::operator!=(const QWebEngineHttpRequest &other) const
如果该对象与other 不同,则返回false
。
另请参见 operator==()。
QWebEngineHttpRequest &QWebEngineHttpRequest::operator=(const QWebEngineHttpRequest &other)
创建other 的副本。
bool QWebEngineHttpRequest::operator==(const QWebEngineHttpRequest &other) const
如果此对象与other 相同,则返回true
(也就是说,如果它们具有相同的方法、URL 和标题)。
另请参见 operator!=().
© 2025 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.