Results 1 to 2 of 2

Thread: Get request's source with QNetworkAccessManager

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

    Question Get request's source with QNetworkAccessManager

    Hello.

    I have a html-page with such source:
    Qt Code:
    1. <html>
    2. <head lang="en">
    3. <script src="http://example1.com/script1.js"></script>
    4. <script src="http://example2.com/script2.js"></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. + '<exampleA.com>/<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 <exampleA.com> should be replaced with example1.com or example2.com, and <scriptA> also should be replaced in the same way).

    As a result I have on my page loaded scripts:
    * http://example1.com/script1.js,
    * http://example1.com/script1-1.js,
    * http://example2.com/script2.js,
    * http://example2.com/script2-1.js.

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

    source
    • example1.com
      • script1.js
      • script1-1.js
      • script1-2.js
    • example2.com
      • script2.js
      • script2-1.js
      • script2-2.js
      • <...>
      • script2-N.js
    • example3.com
      • 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
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    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 place...in 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

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.