c++ - 如何从QT中的http请求中删除授权 header

标签 c++ qt http-headers httprequest

我想从触发的 GET 请求中删除“Authorization:” header 。 QT 默认添加它。

触发请求的示例 -

获取 https://mywebsiteurl.com/remote.php/webdav/3.txt HTTP/1.1


授权:基本Og==

用户代理:Mozilla/5.0 (Linux) myapp/1.2.1

连接:保持事件状态

接受编码:gzip、deflate

接受语言:en-US,*


示例代码-

QNetworkAccessManager* mgr = new QNetworkAccessManager();
QNetworkRequest req;
req.setUrl(QUrl("sampleURL") );
mgr->get(req);

结果应如下所示(没有授权 header )-

获取 https://mywebsiteurl.com/remote.php/webdav/3.txt HTTP/1.1


用户代理:Mozilla/5.0 (Linux) myapp/1.2.1

连接:保持事件状态

接受编码:gzip、deflate

接受语言:en-US,*


可以使用 setHeader、setRawHeader 等 API,但无法完全删除 header 。

最佳答案

QT 似乎通过信号/槽系统自动处理身份验证,与 header 分开,因此您不必考虑它。

您是否正在处理来自 NetworkManager 的 authenticationRequired(QNetworkReply * reply, QAuthenticator * authenticator) 信号。如果它对身份验证请求给出误报,您可以通过重置信号中的身份验证器来解决这个问题。抱歉,这不是一个确定的答案,但如果可行,请告诉我!

This signal is emitted whenever a final server requests authentication before it delivers the requested contents. The slot connected to this signal should fill the credentials for the contents (which can be determined by inspecting the reply object) in the authenticator object.

QNetworkAccessManager will cache the credentials internally and will send the same values if the server requires authentication again, without emitting the authenticationRequired() signal. If it rejects the credentials, this signal will be emitted again.

Note: It is not possible to use a QueuedConnection to connect to this signal, as the connection will fail if the authenticator has not been filled in with new information when the signal returns.

See also proxyAuthenticationRequired().

关于c++ - 如何从QT中的http请求中删除授权 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33543959/

相关文章:

c++ - 如何从 Photoshop 滤镜插件 (Photoshop SDK) 访问 exif 数据字段

qt - QML继承

qt - defaultServiceProvider::requestService(): 找不到服务 - "org.qt-project.qt.camera"

python - 为实时数据绘图实现 pyqtgraph

c# - 使用 HTTP Location Header、HttpWebRequest/Response 和 Response.Cookies.Add() 将用户重定向到使用表单例份验证的身份验证页面

android - flutter - 我的 http 帖子正文中没有发送 json

http-headers - 是否可以发送 401 Unauthorized AND 重定向(带位置)?

c++ - 初始化 std::pair<double, std::array<std::pair<double, double>, 3>>

c++ - 仅 header 库中的静态数据

c++ - 错误 : pasting "tmp_UINT" and "+" does not give a valid preprocessing token