QNetworkReply takes long time to emit finished signal



  • I am trying to read a header value from reply for which I had fired a request. First, it didn't use to give any reply.Later,I added an event loop to know when the Finished signal is received. I now, get the reply properly,but problem now I am facing is that it takes huge time to reply. Nearly 10 seconds..!!! I receive the reply immediately after firing the request.I can see it in fiddler(a packet capturing tool). Why is it taking 10 seconds when it has all the values?

    my chunk of code -

    bool MySampleApp::getStatus()
    {
    QNetworkRequest request;
    QUrl url ("http://www.myapp.com");
    QString strQuery = "myquerytoserver";
    url.setEncodedQuery(strQuery.toUtf8());
    request.setUrl();
    m_networkManager = new QNetworkAccessManager(this);
    request.setSslConfiguration(this->createSslConfig());
    QNetworkReply *reply = m_networkManager->sendCustomRequest(request,"HEAD");

    QEventLoop loop;
    connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); //10 seconds??? why??
    loop.exec();
    
     if(reply)
    {
       reply->deleteLater();
       QByteArray strPresent =  reply->rawHeader("is_present"); // my custom header value sent by server
       if("true" == strPresent)
          return true;
    }
    return false;
    

    }

    Thanks in advance..!!


  • Lifetime Qt Champion

    Hi,

    Are you sure that all data have arrived that soon ? Getting the headers and getting everything that the request has asked for are two different things



  • @SGaist Yes.I immediately get all the data in the response/reply. But, here as I mentioned it takes huge time to emit finished. When multiple requests are fired, their 10 seconds adding up literally hangs up my app.


  • Lifetime Qt Champion

    Does the server keep the connection open too long ?



  • @SGaist No,server doesn't keep connection open to long. Does it have to do something with networkacessmanager? It's used through out the app & some requests have timers associated with them. But, I don't use timer for my this particular request.


  • Lifetime Qt Champion

    How many queries are you sending at the same time ?



  • @SGaist Hi, I resolved the issue. I was actually firing sendCustomRequest() api as I was using a specific url query in request which was needed in to fire via HEAD method. Before firing sendCustomRequest() api I was also creating & resetting my ssl configuration. So, instead I directly now use the head() api to fire my HEAD request. Now,finished signal by reply gets fired instantaneously & I am able to read my specific header value in response in no time.

    Thanks for your time..!! :)



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.