Results 1 to 6 of 6

Thread: HTTP POST method

  1. #1
    Join Date
    Jan 2009
    Posts
    51
    Thanks
    28
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question HTTP POST method

    I have a problem with a HTTP post method.

    Here's an example:
    Go to http://www.ddo.com/, type "BLABLA" in search area and press ENTER.
    You will get "Total: 0 Results found for "BLABLA"".

    I want to reach the same effect using Qt, I tried this:
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. http=new QHttp("www.ddo.com");
    4. connect(http, SIGNAL(readyRead(QHttpResponseHeader)), this, SLOT(readResponse(QHttpResponseHeader)));
    5. http->post("/component/search/", "searchword=BLABLA");
    6. }
    7.  
    8. void MainWindow::readResponse(QHttpResponseHeader header){
    9. qDebug()<<http->readAll();
    10. }
    To copy to clipboard, switch view to plain text mode 
    http->readAll() returns source code of site http://www.ddo.com/component/search/, but in source this expression:
    Total: 0 Results found for "BLABLA"
    doesn't exist. Instead, there's:
    Total: 0 Results found for ""

    So it looks like server didn't receive any post data.
    I tried this on more websites, and every time server ignores my post data.

    What's wrong?

    Thanks in advance!

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: HTTP POST method

    Use a network sniffer and see what is different between your implementation and a web browsers.

  3. #3
    Join Date
    Jan 2009
    Posts
    51
    Thanks
    28
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HTTP POST method

    I captured packets sent by internet browser and my program by WinDump, and everything was the same, except some values from HTTP header.

    Now I used QNetworkAccessManager instead of QHttp and it works, but i don't know why :P

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: HTTP POST method

    So the data sent is exactly the same as before, as verified by WinDump?

  5. #5
    Join Date
    Jan 2009
    Posts
    51
    Thanks
    28
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HTTP POST method

    Data are the same, but header is quiet different (QNetworkAccessManager sends also information about User-Agent etc.).

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: HTTP POST method

    Right, so you do know why. The header is different!

Similar Threads

  1. How to upload file to HTTP server (POST Method)
    By Alex Snet in forum Qt Programming
    Replies: 8
    Last Post: 24th January 2011, 22:49
  2. Http post
    By Max123 in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2010, 13:43
  3. Http Post method help
    By ravirdv in forum Qt Programming
    Replies: 0
    Last Post: 27th September 2009, 12:15
  4. http POST with form encoding
    By srikanth_trulyit in forum Qt Programming
    Replies: 1
    Last Post: 10th June 2009, 10:16
  5. How do I send data with http post request?
    By Morea in forum Qt Programming
    Replies: 13
    Last Post: 21st January 2009, 22:51

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.