Results 1 to 6 of 6

Thread: QHttp : Host vs IP adress

  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default QHttp : Host vs IP adress

    Hello,

    I'm using QHttp objects to fll a form, submit it and download the server response.
    So I made 2 QHttp objects : the first fill the form with a POST header, and the second download the response with a GET header.

    Working under Windows 2000 / XP, I've added the host value in the HOST file of the system :
    Qt Code:
    1. # Copyright (c) 1993-1999 Microsoft Corp.
    2. #
    3. # Ceci est un exemple de fichier HOSTS utilisé par Microsoft TCP/IP
    4. # pour Windows.
    5. #
    6. # Ce fichier contient les correspondances des adresses IP aux noms d'hôtes.
    7. # Chaque entrée doit être sur une ligne propre. L'adresse IP doit être placée
    8. # dans la première colonne, suivie par le nom d'hôte correspondant. L'adresse
    9. # IP et le nom d'hôte doivent être séparés par au moins un espace.
    10. #
    11. # De plus, des commentaires (tels que celui-ci) peuvent être insérés sur des
    12. # lignes propres ou après le nom d'ordinateur. Ils sont indiqué par le
    13. # symbole '#'.
    14. #
    15. # Par exemple :
    16. #
    17. # 102.54.94.97 rhino.acme.com # serveur source
    18. # 38.25.63.10 x.acme.com # hôte client x
    19.  
    20. 127.0.0.1 localhost
    21. 192.168.1.12 courriel
    To copy to clipboard, switch view to plain text mode 

    So my host is "courriel", with the IP adress 192.168.1.12
    Everything forks fine... On my computer .
    When I want to use my application on other computer, I get an error cause the QHttp objects can't find the host value for "courriel". Of course, the HOST file hasn't been edited !

    So, I used directly the IP adress in my application, but then I get a 404 error : host not found .

    Qt Code:
    1. IL_http = new QHttp("192.168.1.12", 80);
    2.  
    3. QHttpRequestHeader header("POST", "/index.php?tg=login&cmd=signon");
    4. header.setValue("Host", "192.168.1.12");
    5. header.setContentType("application/x-www-form-urlencoded");
    6. header.setContentLength(content.length());
    7.  
    8. IL_httpId = IL_http->request(header, content);
    To copy to clipboard, switch view to plain text mode 

    The QHttp constructeur needs a "hostname" and not a "host adress", but is it possible to work directly with an IP adresse ?
    Else, is it possible to set a host reference oly for this application ? like an intrnal host file ?
    Last edited by Nyphel; 10th April 2007 at 15:53.

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHttp : Host vs IP adress

    Hi !

    I've not made a lot of searches, but I think you can't use directly IP addresses...
    You can use the static functions in QHostInfo, for example lookupHost(), that will give you the hostname associated to your IP.

    For your 2nd question, yes
    You can use a map (hostname, ip) to achieve that : check QHash / QMap classes

  3. #3
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QHttp : Host vs IP adress

    Thans Guilugi, I will take a look !

  4. #4
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHttp : Host vs IP adress

    Ooops, sorry, QHostInfo::lookupHost() is the reverse function : it determines IP from hostname

    You should use instead setAddresses() / hostName() to obtain hostnames from IP addresses..

    My mistake

  5. #5
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QHttp : Host vs IP adress

    Thaks for your help .
    I will add this in the DNS and test thoses functions

  6. #6
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp : Host vs IP adress

    I guess you get the 404-error because if you use the ip directly you don't send the Host-HTTP-Header. So the webserver doesn't know which Virtual-Host it should use and uses the default - which might be a different that you expect (depends on your webserver-configuration)

    you can test ist by opening http://192.168.1.12/ in your browser and looking if it is the same as http://courriel/

    lookupHost won't work - as this function just asks a DNS-Server - and as you use the hosts-file you most likely don't have one. (for your local domains)

    niko

Similar Threads

  1. Setting a cookie for a Qhttp connection
    By Nyphel in forum Newbie
    Replies: 16
    Last Post: 5th April 2007, 16:30
  2. Qtopia host side development environment for ARM target.
    By hvreddy1110 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 11th October 2006, 16:05
  3. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 12:19
  4. QHttp related
    By whoops.slo in forum Qt Programming
    Replies: 12
    Last Post: 20th June 2006, 21:57
  5. using Qhttp with www(x) sites
    By importantman in forum Qt Programming
    Replies: 18
    Last Post: 4th April 2006, 01:12

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.