How to reuse QNetworkReply to use HTTP Persistent Connection?



  • Hi all,

    I have an application that accesses REST API from a server. The server limits new connection count to 2 each second. But it allows more requests in a single connection (HTTP persistent connection).

    I use QNetworkReply and QNetworkAccessManager. Qt 5.4.

    From what I read, by default Qt network uses persistent connection. However, the connection will be closed when a reply is deleted.

    My question is, how to reuse QNetworkReply wihout deleting it and create new one for each request? Since I access REST API, there are a lot of different kinds of request with different parameters and request type (get, post, delete, etc). Seems the only way to create and config QNetworkReply is calling QNetworkAccessManager get/post/deleteResource methods. How can I feed different parameters and request type to an existing QNetworkReply?

    Thanks



  • Nobody? I'm thinking about to switch to libcurl with which I can control everything...


  • Moderators

    Maybe the server sends a CLOSE response anyways. Some server implementations do not honor the keep-alive request correctly.
    you can try if libcurl is working at all?
    Also maybe you can sniff the data transfer (especially the request and response headers)?



  • @raven-worx said:

    Maybe the server sends a CLOSE response anyways. Some server implementations do not honor the keep-alive request correctly.
    you can try if libcurl is working at all?
    Also maybe you can sniff the data transfer (especially the request and response headers)?

    The problem is not persistent connection doesn't work, but deleting a QNetworkReply will cause the connection closed. I'm looking for how to reuse existing QNetworkReply.
    Currently when I need a QNetworkReply, I have to call QNetworkAccessManager get/post/deleteResource methods to create a new reply, seems no way to reuse a reply.


  • Moderators

    because this simply makes no sense to reuse a REPLY, since a REPLY is the RESPONSE to a single REQUEST.
    As i said...check the request- and repsonse-headers and see if the webserver even supports a persistent connection properly.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.