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. HTTP status code 101 when trying to make POST request
Forum Updated to NodeBB v4.3 + New Features

HTTP status code 101 when trying to make POST request

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 589 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.
  • nicmoraisN Offline
    nicmoraisN Offline
    nicmorais
    wrote on last edited by
    #1

    Hello everyone.
    I'm trying to make a POST request with QNetworkAccessManager and QNetworkRequest to my API, which was made with Phoenix. The get requests works well, however, the post requests does not. It returns status code 101, and I think that's because there's an "Upgrade" header on that request, which I don't now how to remove. Any suggests?

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

      Hi,

      Did you check to which protocol you switched ?

      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
      • nicmoraisN Offline
        nicmoraisN Offline
        nicmorais
        wrote on last edited by nicmorais
        #3

        Hello SGaist.
        I don't remember switching any procotols. Also, POST Requesting works on curl.
        Here's my code:

        void LoginWidget::postRequest(){
            QUrl serviceUrl = QUrl("http://192.168.31.184:4000/api/users/signin");
            QNetworkRequest request(serviceUrl);
            QJsonObject json;
            json.insert("email","nicolas@email.com");
            json.insert("password","1234");
            QJsonDocument jsonDoc(json);
            QByteArray jsonData= jsonDoc.toJson();
            request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
            request.setHeader(QNetworkRequest::ContentLengthHeader,QByteArray::number(jsonData.size()));
            QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
            QObject::connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
            networkManager->post(request, jsonData);
        }
        
        void LoginWidget::replyFinished(QNetworkReply *reply){
            int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
            qDebug() << "Reponse network error" << reply->error();
            qDebug() << "Reponse HTTP status code" << statusCode;
            qDebug() << "Reply content:" << reply->readAll();
            reply->deleteLater();
        }
        

        The output:
        Reponse network error QNetworkReply::UnknownNetworkError
        Reponse HTTP status code 101
        Reply content: ""

        1 Reply Last reply
        0
        • nicmoraisN Offline
          nicmoraisN Offline
          nicmorais
          wrote on last edited by
          #4

          Solved with

          request.setAttribute(QNetworkRequest::Http2AllowedAttribute, false);
          

          But is this a best practice? I want to know if it's safe, and why.

          1 Reply Last reply
          0
          • nicmoraisN Offline
            nicmoraisN Offline
            nicmorais
            wrote on last edited by
            #5

            Nevermind, I'm implementing HTTPS and this should be safe enough. Thanks a lot!

            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