Results 1 to 4 of 4

Thread: How I get POST variables?

  1. #1
    Join Date
    Nov 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How I get POST variables?

    Hello,

    variables from GET method I get without problem

    Qt Code:
    1. }else if (httpHeader->method() == "GET"){
    2. QUrl* url = new QUrl(httpHeader->path());
    3. QList< QPair<QString, QString> > params = url->queryItems();
    4. QMap<QString, QString> paramsMap;
    5. for(int i=0; i<params.size(); i++){
    6. paramsMap[params[i].first] = params[i].second;
    7. }
    8. ...
    To copy to clipboard, switch view to plain text mode 

    I can work with variables like this: paramsMap["name"]

    But I need use the POST method? How I get variables? Help please...

    I can only get this:
    user-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
    accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    accept-language: en-us,en;q=0.5
    accept-encoding: gzip,deflate
    accept-charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    keep-alive: 300
    connection: keep-alive

    by
    Qt Code:
    1. if(httpHeader->method() == "POST"){
    2. QUrl* url = new QUrl(httpHeader->path());
    3. QList< QPair<QString, QString> > params = httpHeader->values();
    4. for(int i=0; i<params.size(); i++){
    5. out << params[i].first << ": " << params[i].second << endl;
    6. }
    7. ...
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How I get POST variables?

    POST data is transmitted after the headers, so looking for it in the header section won't do you any good. You have to wait until the actual data is downloaded, read it and your variables will be there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How I get POST variables?

    Thx...

    Now I have next problem

    piece of code:
    Qt Code:
    1. ...
    2. QString header = "";
    3. QString line = clientConnection->readLine();
    4. while(line.length() > 0){
    5. obsah = "";
    6. header += line;
    7. line = clientConnection->readLine();
    8. }
    9. ...
    To copy to clipboard, switch view to plain text mode 

    In header is now:

    POST / HTTP/1.1
    Host: localhost:8081
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: cs,en-us;q=0.7,en;q=0.3
    Accept-Encoding: gzip,deflate
    Accept-Charset: windows-1250,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    Referer: localhost/qt/
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 26

    xa=jalsu&odeslat=Z


    In variable odeslat should be Zaindexuj. Line with variables is maximal 18 chars long. Can anyone help pls?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How I get POST variables?

    My guess is you didn't wait until all the data has arrived. Wait for QHttp::requestFinished() signal and then read the data.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QHTTP POST problem
    By oscar in forum Qt Programming
    Replies: 5
    Last Post: 10th October 2009, 19:58
  2. QNetworkAccessManager double post
    By QPlace in forum Qt Programming
    Replies: 1
    Last Post: 11th February 2009, 04:44
  3. QDevelop debuggng - viewing class member variables
    By dbrmik in forum Qt-based Software
    Replies: 0
    Last Post: 7th January 2009, 10:40
  4. creating query string from variables
    By locus in forum General Programming
    Replies: 2
    Last Post: 16th April 2007, 08:50

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.