Results 1 to 5 of 5

Thread: Using QHttp / QUrl with a hard-coded DNS entry

  1. #1
    Join Date
    Mar 2006
    Posts
    46
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Using QHttp / QUrl with a hard-coded DNS entry

    I'm sending a request to a virtual server using QUrl / QHttp that is of the form

    http://www.myserver.com/path/request.php?var1=x&var2=y

    and this is working fine. For certain tests we would like to not use a DNS server and instead hard-code the DNS entry of www.myserver.com to an IPv4 address of our choosing. I know I can do this with a hosts file entry, but I would like to do this only within my app and not affect the rest of the OS. Further, because the virtual server wants to see the correct hostname in the URL, I can't simply make a request like this:

    http://1.2.3.4/path/request.php?var1=x&var2=y

    I haven't gone through the QtNetwork source yet, but I'm wondering if there is a way to specify an "internal" DNS provider or internal hosts mapping so that it does not go through the whole network stack to make these DNS lookups and still has the hostname in the URL, all the while having this only affect a single instance of my app?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Using QHttp / QUrl with a hard-coded DNS entry

    Name lookups are likely to use the QHostInfo class static members. There seems to be no obvious way to subvert this internally.

  3. #3
    Join Date
    Mar 2006
    Posts
    46
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using QHttp / QUrl with a hard-coded DNS entry

    Quote Originally Posted by ChrisW67 View Post
    Name lookups are likely to use the QHostInfo class static members. There seems to be no obvious way to subvert this internally.
    It's looking somewhat doable, but I have to peek into qhostinfo_p.h to pull it off. There is a global instance of a QHostInfoLookupManager that runs a thread pool for DNS lookups but also maintains a public QHostInfoCache which has a put() method where I could stuff a non-DNS lookup cache entry for my hostname. If I do this before I use QHttp it might work... will let everyone know if this works out.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Using QHttp / QUrl with a hard-coded DNS entry

    BTW, you should not be writing new code to use QHttp

  5. #5
    Join Date
    Mar 2006
    Posts
    46
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using QHttp / QUrl with a hard-coded DNS entry

    Quote Originally Posted by ChrisW67 View Post
    BTW, you should not be writing new code to use QHttp
    Thanks - understood. This code is 7 years old, but even with QNetworkAccessManager I think the hostname resolution is going to work the same.

Similar Threads

  1. Replies: 8
    Last Post: 7th December 2012, 15:02
  2. Converting to Model/View from hard-coded trees and tables
    By d_stranz in forum Qt Programming
    Replies: 0
    Last Post: 6th March 2012, 17:46
  3. Qfile Question - hard coded path
    By fortyhideout12 in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2010, 20:50
  4. Replies: 11
    Last Post: 20th January 2009, 14:10
  5. Replies: 16
    Last Post: 4th October 2007, 22:04

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.