PDA

View Full Version : QTcpServer : retrieve the requested URL



fitzy
27th October 2009, 14:03
Hi there!

I have developped a server, its address is 127.0.0.1:4242 ; I'm using QTcpServer, and QTcpSocket (to send the answer).

I would like to be able to know what is the requested URL. :(

For example, if I type this in Firefox :

http://127.0.0.1:4242/directory1/test/

how can I know that firefox wants to access /directory/test/ ?

I tried localAddress(), but it only returns 127.0.0.1



I really need your help guys ! :(

JohannesMunk
27th October 2009, 14:10
Hi there!

You need a HTTP-Server for that.

Have a look at: http://doc.trolltech.com/solutions/4/qtservice/qtservice-example-server.html

HIH

Johannes

fitzy
27th October 2009, 14:19
Thank you but I can't figure out what is the function that gives the requested address in your example :confused:

JohannesMunk
27th October 2009, 14:25
Well.. you need to parse the get command..

http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Example_session



QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
if (tokens[0] == "GET") {


tokens[1] should be the requested url.

Sorry for not having pointed that out .. Maybe you just need to search for a more complete HTTP Server using google?

Johannes

fitzy
27th October 2009, 14:30
Perfect !
Thank you very much ! :cool: