Reputation: 14081
I sent a Qt JSON string > 1024 charaters to PHP (tested both, via multi part and url encoding).
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart textPart;
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"swiftjson\""));
textPart.setBody(QJsonDocument(model.toJson()).toJson(QJsonDocument::Compact));
multiPart->append(textPart);
On the PHP side the JSON string is truncated at 1024 characters for some reason
I have tested:
QUrlQuery
instead of multipart, same situationpost_max_size 20M
Looking for a hint how I can send > 1024 characters
Upvotes: 3
Views: 568
Reputation: 14081
I have figured it out. It is actually the debugger truncating the variables, or more precisely the display is truncated. The actual value is untouched, but I was mislead by the display. Setting the value to 2048 for the debugger solves the issue.
Actually the value in brackets (above screenshot) is the real size, which I thought is the byte size. Once you know ...
Thanks to all who helped.
Upvotes: 0
Reputation: 19112
You probably have to use waitForBytesWritten
with some sort of loop, or use the related signal: bytesWritten
.
http://doc.qt.io/qt-5/qabstractsocket.html#waitForBytesWritten
http://doc.qt.io/qt-5/qiodevice.html#bytesWritten
The loopback example shows how to send a large payload in a response properly.
http://doc.qt.io/qt-5/qtnetwork-loopback-dialog-cpp.html
static const int PayloadSize = 64 * 1024; // 64 KB
static const int TotalBytes = 50 * 1024 * 1024;
connect(&tcpClient, SIGNAL(bytesWritten(qint64)),
this, SLOT(updateClientProgress(qint64)));
// called when the TCP client connected to the loopback server
bytesToWrite = TotalBytes - (int)tcpClient.write(QByteArray(PayloadSize, '@'));
...
void Dialog::updateClientProgress(qint64 numBytes)
{
// callen when the TCP client has written some bytes
// ...
// only write more if not finished and when the Qt write buffer is below a certain size.
if (bytesToWrite > 0 && tcpClient.bytesToWrite() <= 4*PayloadSize)
bytesToWrite -= (int)tcpClient.write(QByteArray(qMin(bytesToWrite, PayloadSize), '@'));
// ...
}
Hope that helps.
Upvotes: 2