QNetworkAccessManager and HTTP persistent connection

假装没事ソ 提交于 2019-12-10 20:14:45

问题


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")));

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.


回答1:


You can do the following to investigate further:

  • Dump the HTTP headers (known and raw) of the outgoing request. You should see a Connection: Keep-Alive header set.
  • Dump the response headers. There should not be a Connection: Close set by the webserver

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.



来源:https://stackoverflow.com/questions/20162767/qnetworkaccessmanager-and-http-persistent-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!