Results 1 to 2 of 2

Thread: Get request's source with QNetworkAccessManager

  1. #1
    Join Date
    Jan 2014
    Qt products
    Qt4 Qt5
    MacOS X Unix/X11 Windows Android

    Question Get request's source with QNetworkAccessManager


    I have a html-page with such source:
    Qt Code:
    1. <html>
    2. <head lang="en">
    3. <script src=""></script>
    4. <script src=""></script>
    5. </head>
    6. <body>
    7. ...
    8. </body>
    9. </html>
    To copy to clipboard, switch view to plain text mode 
    Each of included java-scripts has code like:
    Qt Code:
    1. (function(){
    2. var s = document.createElement('script');
    3. var x = document.getElementsByTagName('script')[0];
    4. s.type = 'text/javascript';
    5. s.async = true;
    6. s.src = ('https:'==document.location.protocol?'https://':'http://')
    7. + '<>/<scriptA>-1.js';
    8. x.parentNode.insertBefore( s, x );
    9. })();
    To copy to clipboard, switch view to plain text mode 
    It means that each of these js-files includes one more external js-file (here is <> should be replaced with or, and <scriptA> also should be replaced in the same way).

    As a result I have on my page loaded scripts:

    Now I need to load my page with QNetworkAccessManager::createRequest() but it's necessary to know who requested each resource. In my example files and were requested by source page, script was requested by script on, script - by script on As a result I need to build tree like this:

      • script1.js
      • script1-1.js
      • script1-2.js
      • script2.js
      • script2-1.js
      • script2-2.js
      • <...>
      • script2-N.js
      • script3.js
      • script3-1.js
      • script3-2.js
      • <...>
      • script3-N.js

    Do you have any ideas how to do it?

  2. #2
    Join Date
    Mar 2009
    Brisbane, Australia
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Unix/X11 Windows
    Wiki edits

    Default Re: Get request's source with QNetworkAccessManager

    I do not know what QNetworkAccessManager::createRequest() has to do with fetching this. QNetworkAccessManager::get() is the tool to fetch the HTML

    You have four problems:
    1. Parsing the returned HTML to extract the target of script links (or inline scripts)
    2. A way to tell the scripts you are interested in from other scripts that will be in the document.
    3. Fetching and executing the identified Javascript to generate the output that would be inserted in its order to run it back through step 1
    4. A data structure to hold the results.

Similar Threads

  1. Replies: 1
    Last Post: 6th February 2013, 13:18
  2. Replies: 4
    Last Post: 7th November 2012, 10:14
  3. Request ID of QNetworkaccessmanager get and post request
    By dineshkumar in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2011, 22:56
  4. sending soap request using QNetworkAccessManager question
    By babymonsta in forum Qt Programming
    Replies: 10
    Last Post: 21st April 2010, 08:55
  5. QNetworkAccessManager get request causing QSslSocket errors
    By Runtime Technologies in forum Qt Programming
    Replies: 5
    Last Post: 29th July 2009, 23:57

Tags for this Thread


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.