gpt4 book ai didi

c++ - Qt中使用GET方法时如何添加token?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:08:22 24 4
gpt4 key购买 nike

我想在 C++/Qt 中的 GET 请求中添加一个 token 。

这是我的 GET/下载方法:

QNetworkReply* DownloadManager::doDownload(const QUrl &url)
{
QNetworkRequest request(url);
QNetworkReply *reply = m_manager.get(request); // m_manager is a QNetworkAcessManager

return reply;
}

最佳答案

token 作为请求 header 的一部分发送,因此对于这种情况,我们使用 setRawHeader()方法:

void QNetworkRequest::setRawHeader(const QByteArray &headerName, const QByteArray &headerValue)

Sets the header headerName to be of value headerValue. If headerName corresponds to a known header (see QNetworkRequest::KnownHeaders), the raw format will be parsed and the corresponding "cooked" header will be set as well.

对于 token ,我们使用以下内容:

request.setRawHeader(QByteArray("Authorization"), QByteArray("Token your_token"));

关于c++ - Qt中使用GET方法时如何添加token?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46033134/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com