Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Getting status code 0 for HTTP post request in qt 5.2
Forum Updated to NodeBB v4.3 + New Features

Getting status code 0 for HTTP post request in qt 5.2

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 1 Posters 4.2k Views 1 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.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    Hi,
    I have built the web services in Ruby on Rails returning Json data, I have checked it through chrome addin and it is working good, returning correct status code on success. So, here I am trying to access these web service but I am getting wrong status code which is 0. Here is my code...but I could not find where I did wrong as I tried to find the problems with logs.

    @ QNetworkAccessManager networkManager;
    QNetworkAccessManager mgr;
    QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
    qDebug() << "Called the C++ slot with message:sssss";
    QUrl url;
    QByteArray postData;
    url.setUrl("http://localhost:3000/api/v1/sessions");
    QNetworkRequest request(url);

        QString postKey = "email";
        QString postValue = "abcd@abcd.com";
        QString postKey1 = "password";
        QString postValue1 = "abcde12345";
    
        postData.append(postKey).append("=").append(postValue).append("&").append(postKey1).append("=").append(postValue1);
        QNetworkReply *reply= networkManager.post(request,postData);
    
        QVariant statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
        int status = statusCode.toInt();
        qDebug() << "Called the C++ slot with message:Correct" << status;
    
        if ( status==200 )
            qDebug() << "Called the C++ slot with message:Correct";
        return;
    
        if ( status != 200 )
        {
            QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
            qDebug() << reason;
        }
    
    }@
    

    Thanks...

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

      Hi,

      If I see things correctly, you don't wait your post to complete before analyzing the reply

      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
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        wait to complete post means shall I put some counter before starting analyzing the reply..correct me if I did not understand your point well.

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

          Use the finished signal and analyze the result in a slot connected to it

          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

          • Login

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