Results 1 to 1 of 1

Thread: QWebPage using invalid base URL for loading with QNetworkReply proxy [SOLVED]

  1. #1
    Join Date
    Sep 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1

    Default QWebPage using invalid base URL for loading with QNetworkReply proxy [SOLVED]

    Hello.

    I'm creating a browser that uses a custom protocol, which could for example be accessed by the URL scheme 'custom', with a URL like

    custom://foo/bar

    I have a QNetworkAccessManager subclass which detects all the requests using that scheme, and creates different QNetworkReply subclasses based on the rest of the content in those URLs.

    One of these custom QNetworkReply objects creates a QNetworkRequest object inside it, passing it a regular HTTP URL to download (I'm testing with "http://google.com"), and initiating a download with my QNetworkAccessManager subclass.

    The QNetworkReply subclass then acts as a proxy for this request made internally, and the QWebFrame seems to load the main HTML content of the Google home-page just fine.

    The problem comes when it tries to load external content. I'm outputting subsequent requests made to my QNetworkAccessManager subclass (in the createRequest() override ... following the initial custom://foo/bar request), and get things like

    "custom://foo/intl/en_com/images/srpr/logo1w.png"

    "custom://foo/images/srpr/nav_logo35.png"

    "custom://foo/extern_js/f/CgJlbhICbnogACswRTgALCswWjgALCswDjgALCswFzgALCswJz gALCswPDgALCswUTgALCswCjgAQB0sKzAWOAAsKzAlOM-IASwrMEA4ACwrMEE4ACwrME04ACwrME44ACwrMFQ4ACwrMGk4A CwrMBg4ACwrMCY4ACyAAjSQAjA/_uiD8tdcvWc.js"

    So it appears to be using the original URL as a base URL for loading the rest of the page content, which is incorrect; it should of course be http://google.com/intl/en_com..., http://google.com/images/srpr/nav..., etc.

    Is there anything I can return from the reply to make the QWebFrame use the right base URL? I did consider splicing the returned data with a <base href="<requested URL base directory as determined by QNetworkReply subclass>"/> put in-between the downloaded <head> element, but this seems messy, and I'm not sure what weird behaviours this might cause later.

    Are there any headers that can be set that will make the QWeb[Page/Frame] look in the right place for external content?

    Any and all assistance is welcomed.

    Edit:

    Solved. There was a much simpler solution to this, don't proxy QNetworkReply at all, and just set a 302 redirect status code on the QNetworkReply subclass to redirect to the appropriate URL for the initial request.
    Last edited by TropicalPenguin; 18th February 2011 at 15:16.

Similar Threads

  1. Unwanted downloads with QWebPage/QWebPage
    By ouekah in forum Newbie
    Replies: 6
    Last Post: 11th May 2010, 23:48
  2. How to use qwebpage in non-gui app
    By Cykus in forum Newbie
    Replies: 4
    Last Post: 10th May 2010, 12:35
  3. Can QWebPage see changes in a website
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 16th August 2009, 00:23
  4. QwebPage within a QGraphicsWidget
    By Osprey in forum Qt Programming
    Replies: 0
    Last Post: 16th June 2009, 18:32
  5. When to delete QNetworkReply?
    By QPlace in forum Qt Programming
    Replies: 5
    Last Post: 11th February 2009, 13:46

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
  •  
Qt is a trademark of The Qt Company.