QHttpMultiPart - failing to post parameters to a php script
-
Hi,
I have a class that uses a QNetworkRequest object to send data to a php script on a server, which would then process the data and post back a reply.
Part of the code to post a parameter was this: -
@
QByteArray& data = netPacket->data;QString bound="---Boundary0xbfffeec9---"; data = QByteArray(QString("--"+bound+"\r\n").toAscii()); data += "Content-Disposition: form-data; name=\"userfilename\"\r\n\r\n"; data += userfilename+ "\r\n"; data += QString("--" + bound + "\r\n").toAscii(); ...
QNetworkAccessManager* m_pHttp;
netPacket->pReply = m_pHttp->post(netRequest,data);
@That worked as expected and "userfilename" appears as a posted parameter to the php script.
I now need to change the code to use QHttpMultiPart, as I need to upload files with the data and don't want to have to load them in memory, but the php script never seems to get any posted parameters.
I'm doing the following: -
@
QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::RelatedType);
QHttpPart textPart1;
textPart1.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain"));
textPart1.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name="userfilename""));
textPart1.setBody(userfilename.toUtf8());
multiPart->append(textPart1);
...
...
m_pHttp->post(request, multiPart);
netPacket->pReply = m_pHttp->post(request, multiPart);
@Can anyone please explain to me where I'm going wrong and why "userfilename" isn't being posted to the web server? The php script is being called, but $_POST in the php script is now empty.
Thanks.
-
There is a bug in QHttpMultiPart.
-
I got the same problem using QHttpMultiPart in uploading files via form....
I googled and found "FormPost":http://www.tuckdesign.com/sources/Qt instead and it worked like a charm. I only modified it to not become a plugin since it was designed as a plugin.
You may wanna try to use it.