Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved How to send QString to server in Qt 5.6?

    QtWebEngine
    qnetworkreply qnetworkrequest qnetworkaccessm network
    3
    7
    2354
    Loading More Posts
    • 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.
    • d1.psy
      d1.psy last edited by d1.psy

      Before, when I was using Qt 5.5, I could send network requests this way:

      QString jsonString = "Some string info";
      uploadManager = new QNetworkAccessManager(this);
      QNetworkRequest rqData (theApp->getDomain() + "PageOnServerName.php"); 
      rqData.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); 
      QNetworkReply * r = uploadManager->post(rqData, jsonString.toLatin1());
      QEventLoop loop; 
      QTimer::singleShot(std::max(10u,timeout_msecs),&loop,SLOT(quit())); 
      r->connect(r, SIGNAL(finished()), &loop, SLOT(quit())); 
      r->connect(r, SIGNAL(error(QNetworkReply::NetworkError)), &loop, SLOT(quit())); 
      loop.exec();
      

      But right now it doesn't seem to work anymore. Server doesn't get any information

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        You should check whether you get any error from the query.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        d1.psy 1 Reply Last reply Reply Quote 0
        • raven-worx
          raven-worx Moderators last edited by

          any warnings in the console?
          What is the server address? In case it's a https-conenction check if your applciation can find the OpenSSL libraries.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply Reply Quote 0
          • d1.psy
            d1.psy @SGaist last edited by

            @raven-worx turns out there's problem with cookies for some reason. uploadManager contains different cookies. For example cookies should be "PHPSESSION = 12345", but uploadManager has "PHPSESSION = 67890". That's why it says "Invalid session" everytime. How do I set right cookies to uploadManager? I've tried uploadManager->cookieJar()->cookiesForUrl(QUrl("http://page.com/PageOnServerName.php")); and it still gives me wrong cookies. Any suggestions?

            raven-worx 1 Reply Last reply Reply Quote 0
            • raven-worx
              raven-worx Moderators @d1.psy last edited by

              @d1.psy
              make sure you reuse the same QNetworkAccessManager instance. When the server sends you a cookie, the QNAM stores it automatically and reuses them in the next request.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              d1.psy 1 Reply Last reply Reply Quote 0
              • d1.psy
                d1.psy @raven-worx last edited by

                @raven-worx in QT 5.5 I had this function

                QNetworkAccessManager *MainWindow::manager ()  {
                    if (getView()) {
                        if (getView()->page()) {
                            QNetworkAccessManager *p =  getView()->page()->networkAccessManager();
                			return p;
                        }
                    }
                

                And manager was used to send post requests to server. It had right cookies

                QNetworkReply * r = manager()->post(rqData, jsonString.toLatin1());
                

                but since QWebEngine doesn't with QNAM, I'm using this

                QNetworkAccessManager *MainWindow::manager ()  {
                    if (getView()) {
                        if (getView()->page()) {
                			return uploadManager;
                        }
                    }
                
                QNetworkReply * r = uploadManager->post(rqData, jsonString.toLatin1());
                

                and uploadManager is using wrong cookies

                raven-worx 1 Reply Last reply Reply Quote 0
                • raven-worx
                  raven-worx Moderators @d1.psy last edited by

                  @d1.psy
                  so you want the cookies from the requests you already made with QtWebEngine?
                  If so take a look at QWebEngineCookieStore (see it's signals) and "sync" the cookies into your QNAM.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post