Results 1 to 9 of 9

Thread: How to cache all network traffic including POST?

  1. #1
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to cache all network traffic including POST?

    Hello,

    I have a QWebView and want to cache all network traffic so that can interact with the exact same webpage later when offline.

    I first looked at QNetworkDiskCache and I understand would need to set PreferCache and then override the Expires header to avoid the content expiring. However the cache interface just takes a QUrl, so would only be for GET requests and I also need to cache POST requests.

    If I override QNetworkAccessManager::createRequest is there a way to create a QNetworkReply instance that already has the content instead of downloading? If so then the network traffic could be manually cached and loaded here.

    thanks,
    Richard

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,396
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to cache all network traffic including POST?

    Well, QNetworkReply is a QIODevice, so it should be possible to override the readData/writeData methods.
    It mostly depends if you can intercept/manipulate its state handling as well.

    Cheers,
    _

  3. #3
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to cache all network traffic including POST?

    That is a good idea, however wouldn't Qt still be downloading the content and emitting errors when offline?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,396
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to cache all network traffic including POST?

    Well, that would depend on what your QNetworkReply implementation would be doing.

    Cheers,
    _

  5. #5
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to cache all network traffic including POST?

    So is it possible to prevent the QNetworkReply downloading?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,396
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to cache all network traffic including POST?

    Quote Originally Posted by rbp View Post
    So is it possible to prevent the QNetworkReply downloading?
    Well, you are the one implementing a custom QNetworkReply subclass, you tell us.

    Cheers,
    _

  7. #7
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to cache all network traffic including POST?

    not sure if you meant to be snarky, but I didn't see an example for this case or method in the documentation that would allow controlling network activity.
    Does anyone else know? Or is there a proper way to approach caching rather than hacking QIDevice?

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,396
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to cache all network traffic including POST?

    I had assumed that you had tried or at least had a look at the implementation in QNetworkAccessManager, but you are of course welcome to wait.

    Cheers,
    _

  9. #9
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to cache all network traffic including POST?

    yes you assume right, which should be obvious from initial post...

    I found some similar work, so hopefully can build off it:
    https://blogs.kde.org/2010/08/28/imp...-qnetworkreply

Similar Threads

  1. Sending HTTP POST network request
    By Ashley in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2015, 21:41
  2. Replies: 1
    Last Post: 10th January 2013, 08:34
  3. implementing network cache using qiodevice
    By derektmm in forum Newbie
    Replies: 8
    Last Post: 24th August 2011, 15:39
  4. QT cannot read continuation or non-http traffic
    By SailingDreams in forum Qt Programming
    Replies: 9
    Last Post: 6th June 2009, 20:53

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.