PDA

View Full Version : QHTTP POST problem



oscar
9th October 2008, 11:11
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




void MyExport::sendHealthCase(QString recipient) {
QString person = "type=healthcase";
person += "&recipient=" + recipient;
person += "&from=" + email;
Patient patient = Patient::get(patientId);
person += "&table=person";
person += "&civilStatus=" + QString::number(patient.civilStatus);
person += "&surname=" + patient.surname;
connect(http, SIGNAL(requestFinished(int, bool)),
this, SLOT(healthCaseFinished(int, bool)));

http->post( QString("/software/send.php"), person.toUtf8());
}

yuriry
9th October 2008, 17:06
Have you tried using this kind of get?



// Note the question mark here \
http->get(QString("/software/send.php?") + person);

oscar
10th October 2008, 08:44
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

oscar
10th October 2008, 13:50
Well, the following solution is working:


QString person="type=healthcase&recipient=test@test.com";
QHttpRequestHeader header("POST", "/software/send.php");
header.setValue("Content-Type", "application/x-www-form-urlencoded");
header.setValue("Host", "dopcica.org");
buffer = new QBuffer();
http->request(header,person.toAscii(),buffer);

Regards,
Oscar

krunoslav
20th December 2008, 22:39
Look here: http://www.tuckdesign.com/products#formpost for complete solution that will allow you even to upload files to web forms.

krunoslav
10th October 2009, 19:58
Moved here (and free now): http://www.tuckdesign.com/sources/Qt.