我添加
m_request.setRawHeader("Connection", "close");
但是使用Wireshark
进行检查时,我发现标头包含一个"Keep-Alive"
。
我调试了Qt
,发现“ network / access / qhttpnetworkconnection.cpp ”
设置Keep-Alive
忽略我的标题。
void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair)"
...
if (networkProxy.type() == QNetworkProxy::HttpCachingProxy) {
value = request.headerField("proxy-connection");
if (value.isEmpty())
request.setHeaderField("Proxy-Connection", "Keep-Alive");
} else {
#endif
value = request.headerField("connection");
if (value.isEmpty())
request.setHeaderField("Connection", "Keep-Alive");
#ifndef QT_NO_NETWORKPROXY
}
有人知道如何设置“连接:关闭”吗?
-
编辑:似乎不可能
QNetworkRequest:能够取消设置一些可选的标头条目 https://bugreports.qt.io/browse/QTBUG-9463
8岁的错误仍未解决...