Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkAccessManager is not sending data part of POST request
QtWS25 Last Chance

QNetworkAccessManager is not sending data part of POST request

Scheduled Pinned Locked Moved Solved General and Desktop
qnetworkaccessmhttp-post
4 Posts 3 Posters 3.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CupaMurdosanC Offline
    CupaMurdosanC Offline
    CupaMurdosan
    wrote on last edited by CupaMurdosan
    #1

    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:

    project.pro:

    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.

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      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 :)

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • CupaMurdosanC Offline
          CupaMurdosanC Offline
          CupaMurdosan
          wrote on last edited by
          #4

          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].

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved