Results 1 to 6 of 6

Thread: QHTTP POST problem

  1. #1
    Join Date
    Sep 2007
    Posts
    31
    Thanked 1 Time in 1 Post

    Default QHTTP POST problem

    Hi,

    The following code doesn't work...
    Before calling this method, the http class worked good by initially calling sethost method and then several get methods.

    But then I need to send a lot of variables, so the POST method is necessary.

    I tested a POST html form to valid my PHP script send.php. Everything is ok.

    Also, the SLOT requestFinished is called and no errors are reported...

    Any idea? Or a functional POST method example?

    Thanks
    Oscar


    Qt Code:
    1. void MyExport::sendHealthCase(QString recipient) {
    2. QString person = "type=healthcase";
    3. person += "&recipient=" + recipient;
    4. person += "&from=" + email;
    5. Patient patient = Patient::get(patientId);
    6. person += "&table=person";
    7. person += "&civilStatus=" + QString::number(patient.civilStatus);
    8. person += "&surname=" + patient.surname;
    9. connect(http, SIGNAL(requestFinished(int, bool)),
    10. this, SLOT(healthCaseFinished(int, bool)));
    11.  
    12. http->post( QString("/software/send.php"), person.toUtf8());
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHTTP POST problem

    Have you tried using this kind of get?

    Qt Code:
    1. // Note the question mark here \
    2. http->get(QString("/software/send.php?") + person);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2007
    Posts
    31
    Thanked 1 Time in 1 Post

    Default Re: QHTTP POST problem

    Yes Yuriry,

    It's working with the GET method.

    But the GET method is too limited (there's a maximum length) when you need to transfer a lot of data which is my case.

    Regards,
    Oscar

  4. #4
    Join Date
    Sep 2007
    Posts
    31
    Thanked 1 Time in 1 Post

    Default Re: QHTTP POST problem

    Well, the following solution is working:

    Qt Code:
    1. QString person="type=healthcase&recipient=test@test.com";
    2. QHttpRequestHeader header("POST", "/software/send.php");
    3. header.setValue("Content-Type", "application/x-www-form-urlencoded");
    4. header.setValue("Host", "dopcica.org");
    5. buffer = new QBuffer();
    6. http->request(header,person.toAscii(),buffer);
    To copy to clipboard, switch view to plain text mode 

    Regards,
    Oscar

  5. #5

    Default Re: QHTTP POST problem

    Look here: http://www.tuckdesign.com/products#formpost for complete solution that will allow you even to upload files to web forms.

  6. #6

    Default Re: QHTTP POST problem

    Moved here (and free now): http://www.tuckdesign.com/sources/Qt.

Similar Threads

  1. QHttp proxy problem
    By andre.rigon in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2008, 21:19
  2. problem in using QHttp
    By Ferdous in forum Newbie
    Replies: 4
    Last Post: 10th September 2008, 12:07
  3. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  4. QHttp download file problem.
    By fengtian.we in forum Qt Programming
    Replies: 12
    Last Post: 12th June 2007, 09:39
  5. QHttp Problem
    By musaulker in forum Newbie
    Replies: 4
    Last Post: 29th March 2007, 00:40

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.