PDA

View Full Version : QHttp : Host vs IP adress



Nyphel
10th April 2007, 14:37
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 :

# Copyright (c) 1993-1999 Microsoft Corp.
#
# Ceci est un exemple de fichier HOSTS utilisé par Microsoft TCP/IP
# pour Windows.
#
# Ce fichier contient les correspondances des adresses IP aux noms d'hôtes.
# Chaque entrée doit être sur une ligne propre. L'adresse IP doit être placée
# dans la première colonne, suivie par le nom d'hôte correspondant. L'adresse
# IP et le nom d'hôte doivent être séparés par au moins un espace.
#
# De plus, des commentaires (tels que celui-ci) peuvent être insérés sur des
# lignes propres ou après le nom d'ordinateur. Ils sont indiqué par le
# symbole '#'.
#
# Par exemple :
#
# 102.54.94.97 rhino.acme.com # serveur source
# 38.25.63.10 x.acme.com # hôte client x

127.0.0.1 localhost
192.168.1.12 courriel

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 :mad:.



IL_http = new QHttp("192.168.1.12", 80);

QHttpRequestHeader header("POST", "/index.php?tg=login&cmd=signon");
header.setValue("Host", "192.168.1.12");
header.setContentType("application/x-www-form-urlencoded");
header.setContentLength(content.length());

IL_httpId = IL_http->request(header, content);


The QHttp constructeur needs a "hostname" and not a "host adress", but is it possible to work directly with an IP adresse ? :o
Else, is it possible to set a host reference oly for this application ? like an intrnal host file ? :)

guilugi
10th April 2007, 15:13
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

Nyphel
10th April 2007, 15:17
Thans Guilugi, I will take a look :) !

guilugi
10th April 2007, 15:22
Ooops, sorry, QHostInfo::lookupHost() is the reverse function : it determines IP from hostname :p

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

My mistake

Nyphel
11th April 2007, 09:19
Thaks for your help :).
I will add this in the DNS and test thoses functions ;)

niko
15th April 2007, 11:21
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