Results 1 to 2 of 2

Thread: QNetworkAccessManager: disable cache for concrete document

  1. #1
    Join Date
    Dec 2009
    Posts
    2
    Qt products
    Qt Jambi
    Platforms
    Windows

    Default QNetworkAccessManager: disable cache for concrete document

    Hi,
    I don't want to cache concrete image on website page (using many qwebview for one site). For this I overload QNetworkAccessManager's method createRequest(), make condition for my image (if (myReq.url() == myUrl) then not apply
    cache), and try in this condition:
    1) myReq.setRawHeader( new QByteArray("Cache-Control"), new QByteArray("no-cache") ); //not work
    2) myReq.setRawHeader( new QByteArray("If-Modified-Since""), new QByteArray(myTime) ); //not work
    3) myReq.setUrl(new QUrl(url2 + "&x=" + rand.nextInt(1000000))); //not work too, url becomes really other, but however image in cache.

    How I must abolish cash for document (in my case - image)? Thanks.
    p.s. sorry for my english

  2. #2
    Join Date
    Dec 2009
    Posts
    2
    Qt products
    Qt Jambi
    Platforms
    Windows

    Default Re: QNetworkAccessManager: disable cache for concrete document

    Probably I explained badly.
    There is a lot of threads, each of them using QWebView. Also we have one url for each of them.
    Task: to compel createRequest (method of QNetworkAccessManager) to take a resource (in my case it is gif-image on website) from the network, instead of from cache.

    Some code of one thread:
    Qt Code:
    1. this.webPage.page().setNetworkAccessManager(new CorrectNetworkAccessManager(this.ip, this.port));
    2. this.webPage.load(this.url);
    To copy to clipboard, switch view to plain text mode 
    Code of class CorrectNetworkAccessManager (which extends QNetworkAccessManager):
    Qt Code:
    1. class CorrectNetworkAccessManager extends QNetworkAccessManager
    2. {
    3. int _port;
    4. String _ip, userAgent, acceptLanguage, acceptCharset;
    5.  
    6. public CorrectNetworkAccessManager(String ip, int port)
    7. {
    8. this._ip = ip;
    9. this._port = port;
    10. }
    11.  
    12. @Override
    13. protected QNetworkReply createRequest(Operation op, QNetworkRequest request, QIODevice outgoingData)
    14. {
    15. QNetworkRequest myReq = new QNetworkRequest(request);
    16.  
    17. /*This show url of each resource of webpage. If number of threads is 10 and webpage contains, for example, gif-image
    18. (<img src="myimage.gif">), this method show us only ONE gif-image url, and it is necessary to do, that 10 showed. I.e.
    19. to abolish cache for this picture. However, if webpage contains php-page, it show 10 times! (because php-page not
    20. caching) */
    21. System.out.println(myReq.url());
    22.  
    23. this.userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko)";
    24. this.acceptLanguage = "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4";
    25. this.acceptCharset = "windows-1251,utf-8;q=0.7,*;q=0.3";
    26.  
    27. myReq.setRawHeader( new QByteArray("User-Agent"), new QByteArray(this.userAgent) );
    28. myReq.setRawHeader( new QByteArray("Accept-Charset"), new QByteArray(this.acceptCharset) );
    29. myReq.setRawHeader( new QByteArray("Accept-Language"), new QByteArray(this.acceptLanguage) );
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 
    How to abolish cach for image? Thanks for answers.
    Last edited by serg_hd; 18th December 2009 at 14:08.

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.