QNetworkAccessManager is not sending data part of POST request
-
When sending POST data to server, from Qt application looks everything good but data part of HTTP part were not sent. In Wireshark in POST packet is visible correct "Content-Length" value but size of whole HTTP segment is only about 226 bytes (is independent on POST data size).
Here is simplified source code:
QT += widgets QT -= gui QT += network CONFIG += c++11 TARGET = POSTrequest CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp
main.cpp:
#include <QObject> #include <QApplication> #include <QNetworkAccessManager> #include <QNetworkRequest> #include <QUrl> int main(int argc, char *argv[]) { QApplication a(argc, argv); QNetworkAccessManager manager; QByteArray array = "a=aaaaaaaaaaaaaa..."; // content length > 500 QNetworkRequest r( QUrl("http://www.server.com/index.php") ); r.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QEventLoop loop; QObject::connect(&manager, SIGNAL(finished(QNetworkReply *)), &loop, SLOT(quit())); manager.post(r, array); loop.exec(); return a.exec(); }
I can't find reason why data part is not send. What I doing wrong? Or, its bug?
Application is running in console.
Using Qt 5.6.0. -
Hi @CupaMurdosan,
Why are you instantiating your own QEventLoop?
What happens if you leave out the QEventLoop entirely (I don't think it should be necessary). Instead of connecting to the loop's quit slot, you should be able to connect to the application's quit slot directly, eg:
int main(int argc, char *argv[]) { QApplication a(argc, argv); ... //QEventLoop loop; //QObject::connect(&manager, SIGNAL(finished(QNetworkReply *)), &loop, SLOT(quit())); QObject::connect(&manager, SIGNAL(finished(QNetworkReply *)), &a, SLOT(quit())); manager.post(r, array); //loop.exec(); return a.exec(); }
Give that a go :)
-
Hi and welcome to devnet,
To add to @paul-colby, you should also connect the error signal to see whether there's something wrong going on.
-
Thank you guys for your replies. Problem is solved - I was wrong with wireshark - data were sent in another packet [TCP segment of a reassembled PDU].