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 double request
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager double request

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 804 Views 2 Watching
  • 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.
  • piervalliP Offline
    piervalliP Offline
    piervalli
    wrote on last edited by
    #1

    Hello,
    I have a server where I send the data without authentication, the timeout on QNetworkAccessManager is 20s, if the server is restarted when I send the data QNetworkAccessManager resend the data without notification. Have you a idea to remove the second request?

        QCoreApplication a(argc, argv);
        QNetworkRequest request;
        const QString m_urlRequest("http://127.0.0.1:3030/service.cgi");
        const QString buffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Service></Service>");
        request.setUrl(m_urlRequest);
        request.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(buffer.size()));
        request.setRawHeader("Content-Type", "application/xml");
        qDebug() << "size" << buffer.size() << request.url().toString() << QString(buffer);
        QNetworkAccessManager *m_manager = new QNetworkAccessManager(&a);
        m_manager->setTransferTimeout(20000);
        QNetworkReply* reply = m_manager->post(request,buffer.toUtf8());
    
        QAbstractSocket::connect(reply, &QNetworkReply::readyRead, [](){
                qDebug() << "readyRead";
        });
        QAbstractSocket::connect(reply, &QNetworkReply::uploadProgress, [](qint64 bytesSent, qint64 bytesTotal){
            qDebug() << "uploadProgress" << bytesSent << bytesTotal;
        });
        return a.exec();
    

    Thanks

    jsulmJ 1 Reply Last reply
    0
    • piervalliP piervalli

      Hello,
      I have a server where I send the data without authentication, the timeout on QNetworkAccessManager is 20s, if the server is restarted when I send the data QNetworkAccessManager resend the data without notification. Have you a idea to remove the second request?

          QCoreApplication a(argc, argv);
          QNetworkRequest request;
          const QString m_urlRequest("http://127.0.0.1:3030/service.cgi");
          const QString buffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Service></Service>");
          request.setUrl(m_urlRequest);
          request.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(buffer.size()));
          request.setRawHeader("Content-Type", "application/xml");
          qDebug() << "size" << buffer.size() << request.url().toString() << QString(buffer);
          QNetworkAccessManager *m_manager = new QNetworkAccessManager(&a);
          m_manager->setTransferTimeout(20000);
          QNetworkReply* reply = m_manager->post(request,buffer.toUtf8());
      
          QAbstractSocket::connect(reply, &QNetworkReply::readyRead, [](){
                  qDebug() << "readyRead";
          });
          QAbstractSocket::connect(reply, &QNetworkReply::uploadProgress, [](qint64 bytesSent, qint64 bytesTotal){
              qDebug() << "uploadProgress" << bytesSent << bytesTotal;
          });
          return a.exec();
      

      Thanks

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @piervalli said in QNetworkAccessManager double request:

      if the server is restarted when I send the data QNetworkAccessManager resend the data without notification

      Do you mean the server sends the reply again?
      Then you would need to check the server implementation.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      piervalliP 1 Reply Last reply
      0
      • jsulmJ jsulm

        @piervalli said in QNetworkAccessManager double request:

        if the server is restarted when I send the data QNetworkAccessManager resend the data without notification

        Do you mean the server sends the reply again?
        Then you would need to check the server implementation.

        piervalliP Offline
        piervalliP Offline
        piervalli
        wrote on last edited by
        #3

        @jsulm
        Generally, the server response after 65s, When I have double request updateProgres of QNetworkReply print two time.
        Now I use curl con QProcess, It work correctly.

        curl -X POST http://1.1.1.1
        -H "Content-Type: application/xml"
        -H "Accept: application/xml"
        -d @file.xml
        I'm not sure but it seems that when the request takes a long time the request is resent.

        jsulmJ 1 Reply Last reply
        0
        • piervalliP piervalli

          @jsulm
          Generally, the server response after 65s, When I have double request updateProgres of QNetworkReply print two time.
          Now I use curl con QProcess, It work correctly.

          curl -X POST http://1.1.1.1
          -H "Content-Type: application/xml"
          -H "Accept: application/xml"
          -d @file.xml
          I'm not sure but it seems that when the request takes a long time the request is resent.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @piervalli said in QNetworkAccessManager double request:

          it seems that when the request takes a long time the request is resent

          I doubt it. But you can check on the server side how many requests you got.

          "updateProgres of QNetworkReply print two time" - do you mean your lambda connected to QNetworkReply::uploadProgress is called two times? But that is normal. What exactly is printed (bytesSent/bytesTotal)?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          piervalliP 1 Reply Last reply
          0
          • jsulmJ jsulm

            @piervalli said in QNetworkAccessManager double request:

            it seems that when the request takes a long time the request is resent

            I doubt it. But you can check on the server side how many requests you got.

            "updateProgres of QNetworkReply print two time" - do you mean your lambda connected to QNetworkReply::uploadProgress is called two times? But that is normal. What exactly is printed (bytesSent/bytesTotal)?

            piervalliP Offline
            piervalliP Offline
            piervalli
            wrote on last edited by piervalli
            #5

            Thanks for replay,

            I have create a clone of server with Node, the server is very easy.
            The request takes 80s before to have a response.

            The test is done is that mode:

            1, request
            2. restart server after 10-30s

            The server node has a log where it writes the request.
            If i send the request with curl or browser this work correctly instead with Qt send the request two time.

            Now as workarround I have included cur as shared library it works correctly, I should be a bug of Qt.
            Thanks

            1 Reply Last reply
            0
            • piervalliP Offline
              piervalliP Offline
              piervalli
              wrote on last edited by
              #6

              Hi
              about this topic there are many request, a additional tickets are:
              https://bugreports.qt.io/browse/QTBUG-67161
              https://bugreports.qt.io/browse/QTBUG-134694

              In the version of Qt 6.9.1 I found that:
              10e546f015e QNetworkAccessManager: don't resend non-idempotent requests Non-idempotent requests are no longer incorrectly re-sent if the connection breaks down while reading the response.

              Codereview:
              https://codereview.qt-project.org/c/qt/qtbase/+/633298

              After many year is it fixed !!!
              is time to forgot Curl for rest request?

              :-)

              1 Reply Last reply
              1

              • Login

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