Results 1 to 3 of 3

Thread: QTcpServer as a HTTPServer + POST Requests

  1. #1
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default QTcpServer as a HTTPServer + POST Requests

    Hey @all,

    I'm using QTcpServer as my HTTPServer. When I get a HTTP GET Request all working fine, but how I can handle a HTTP POST Request?

    Here is the code where i read from the client:
    Qt Code:
    1. void HttpServer::readClient() {
    2. if (disabled)
    3. return;
    4.  
    5. QTcpSocket* socket = (QTcpSocket*)sender();
    6. if (socket->canReadLine()) {
    7. QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
    8.  
    9. qDebug() << "QStringList ---------";
    10. for (QList<QString>::iterator i = tokens.begin(); i != tokens.end(); ++i)
    11. qDebug() << (*i);
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    What I see with a GET Request (http://127.0.0.1:84/index.html?first...e=Mustermann):
    Qt Code:
    1. QStringList ---------
    2. "GET"
    3. "/index.html?firstname=Max&lastname=Mustermann"
    4. "HTTP/1.1"
    5. ""
    To copy to clipboard, switch view to plain text mode 

    And here i see something about the POST REQUEST (http://127.0.0.1:84/index.html):
    Qt Code:
    1. QStringList ---------
    2. "POST"
    3. "/"
    4. "HTTP/1.0"
    5. ""
    To copy to clipboard, switch view to plain text mode 

    How can i read POST Variables?

    Regards
    NoRulez

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer as a HTTPServer + POST Requests

    You just read the first line, but in POST request data comes after the request header.

  3. #3
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: QTcpServer as a HTTPServer + POST Requests

    thanks

    currently i wrote:
    Qt Code:
    1. while (socket->canReadLine()) {
    To copy to clipboard, switch view to plain text mode 
    instead of
    Qt Code:
    1. if (socket->canReadLine()) {
    To copy to clipboard, switch view to plain text mode 
    and all will work like a charm :-)

    Much thanks and Regards

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.