QNetworkAccessManager 和 HTTP 持久连接 [英] QNetworkAccessManager and HTTP persistent connection

查看:77
本文介绍了QNetworkAccessManager 和 HTTP 持久连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTTP 1.1 默认支持持久连接,因此我想使用在发出第一个 HTTP 请求时设置的相同连接发送我的第二个 http 请求.如何通过 Qt 实现这一点?

HTTP 1.1 supports persistent connection by default, so I want to send my a second http request using the same connection that was setup when the first HTTP request was made. how can this be achieved through Qt?

如果我只是在第一个请求完成后发出第二个请求,如下所示

If I simply make the second request after the first one finished like the following

manager->get(QNetworkRequest(QUrl("http://qt-project.org")));

似乎将启动到服务器的新 TCP 连接(我已使用网络嗅探器检查过)实验还说:如果回复是deleteLater()或abort()内结束()信号,连接将被关闭.

it seems a new TCP connection to the server will be initiated (I have checked with a network sniffer) The experiment also says: If the reply is deleteLater() or abort() within finished() signal, the connection will be closed.

推荐答案

您可以执行以下操作以进一步调查:

You can do the following to investigate further:

  • 转储传出请求的 HTTP 标头(已知和原始).您应该会看到一个 Connection: Keep-Alive 标头集.
  • 转储响应标头.应该有 not 由网络服务器设置的 Connection: Close

有时网络服务器不接受 keep-alive 标头,无论如何都会发送 close.在这种情况下,客户端正确地关闭了连接.

Sometimes webservers don't honor the keep-alive header and will send a close anyway. In this case the client is rightfully closing the connection.

这篇关于QNetworkAccessManager 和 HTTP 持久连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆