Results 1 to 5 of 5

Thread: QTcpServer : retrieve the requested URL

  1. #1
    Join Date
    Oct 2009
    Posts
    38
    Thanks
    13
    Platforms
    Unix/X11 Windows

    Default QTcpServer : retrieve the requested URL

    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 :
    Qt Code:
    1. http://127.0.0.1:4242/directory1/test/
    To copy to clipboard, switch view to plain text mode 

    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 !
    Last edited by fitzy; 27th October 2009 at 14:11.

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer : retrieve the requested URL

    Hi there!

    You need a HTTP-Server for that.

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

    HIH

    Johannes

  3. The following user says thank you to JohannesMunk for this useful post:

    fitzy (27th October 2009)

  4. #3
    Join Date
    Oct 2009
    Posts
    38
    Thanks
    13
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer : retrieve the requested URL

    Thank you but I can't figure out what is the function that gives the requested address in your example

  5. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer : retrieve the requested URL

    Well.. you need to parse the get command..

    http://en.wikipedia.org/wiki/Hyperte...xample_session

    Qt Code:
    1. QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
    2. if (tokens[0] == "GET") {
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by JohannesMunk; 27th October 2009 at 14:30.

  6. The following user says thank you to JohannesMunk for this useful post:

    fitzy (27th October 2009)

  7. #5
    Join Date
    Oct 2009
    Posts
    38
    Thanks
    13
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer : retrieve the requested URL

    Perfect !
    Thank you very much !

Similar Threads

  1. QTcpServer and port problem
    By Talei in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2009, 18:01
  2. QTcpServer & QTcpSocket questions...
    By jxmot in forum Qt Programming
    Replies: 2
    Last Post: 24th April 2008, 21:38

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.