QNetworkAccessManager double request
-
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
-
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
@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. -
@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.@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. -
@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.@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)?
-
@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)?
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-30sThe 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 -
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-134694In 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/+/633298After many year is it fixed !!!
is time to forgot Curl for rest request?:-)