Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. How to send QString to server in Qt 5.6?
QtWS25 Last Chance

How to send QString to server in Qt 5.6?

Scheduled Pinned Locked Moved Unsolved QtWebEngine
qnetworkreplyqnetworkrequestqnetworkaccessmnetwork
7 Posts 3 Posters 3.0k Views
  • 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.
  • D Offline
    D Offline
    d1.psy
    wrote on 24 Aug 2016, 11:02 last edited by d1.psy
    #1

    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
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Aug 2016, 21:02 last edited by
      #2

      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

      D 1 Reply Last reply 31 Aug 2016, 17:40
      0
      • R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 25 Aug 2016, 06:47 last edited by
        #3

        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
        0
        • S SGaist
          24 Aug 2016, 21:02

          Hi,

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

          D Offline
          D Offline
          d1.psy
          wrote on 31 Aug 2016, 17:40 last edited by
          #4

          @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?

          R 1 Reply Last reply 31 Aug 2016, 17:42
          0
          • D d1.psy
            31 Aug 2016, 17:40

            @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?

            R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 31 Aug 2016, 17:42 last edited by
            #5

            @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

            D 1 Reply Last reply 31 Aug 2016, 18:05
            0
            • R raven-worx
              31 Aug 2016, 17:42

              @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.

              D Offline
              D Offline
              d1.psy
              wrote on 31 Aug 2016, 18:05 last edited by
              #6

              @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

              R 1 Reply Last reply 31 Aug 2016, 18:25
              0
              • D d1.psy
                31 Aug 2016, 18:05

                @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

                R Offline
                R Offline
                raven-worx
                Moderators
                wrote on 31 Aug 2016, 18:25 last edited by
                #7

                @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
                0

                7/7

                31 Aug 2016, 18:25

                • Login

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