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
Forum Update on Monday, May 27th 2025

HTTP

Scheduled Pinned Locked Moved Solved General and Desktop
http getpostserver - client
13 Posts 3 Posters 3.8k 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.
  • P Offline
    P Offline
    Pranit Patil
    wrote on 20 Jun 2018, 10:10 last edited by
    #1

    Any One working on Http in Qt application i need a help ?
    how to send data on server using http protocol

    @Embedded Software Developer
    God has given you one face, and you make yourself another.

    J 1 Reply Last reply 20 Jun 2018, 10:14
    0
    • P Pranit Patil
      20 Jun 2018, 10:10

      Any One working on Http in Qt application i need a help ?
      how to send data on server using http protocol

      J Offline
      J Offline
      jazzycamel
      wrote on 20 Jun 2018, 10:14 last edited by
      #2

      @Pranit-Patil The QNetwork module, specifically the QNetworkAccessManager and the associated QNetworkRequest and QNetwork reply classes are what you need.

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      1 Reply Last reply
      2
      • P Offline
        P Offline
        Pranit Patil
        wrote on 20 Jun 2018, 10:21 last edited by
        #3

        I am trying to send following data on "https://dev.datoms.io/api/trade/initialization/create_device"

        Data:
        //POST /api/trade/initialization/create_device HTTP/1.1
        //Host: dev.datoms.io
        //Cache-Control: no-cache
        //Postman-Token: 2f521ea3-8688-4fd2-b8f5-0fc7f3df62ba

        Real data {"user_token":"Ej14qoqnm9PxZJWXXHPIzX8L2owzQuIPHA0QewilGs8fzScwp6XoPnsQ4KUb71iv","qr_code":"QG0Z9Q5J","circuit_version":"","device_type":1}

        if i send data successfully i will get response from server .
        im trying to implement but not getting.
        Thank You.

        @Embedded Software Developer
        God has given you one face, and you make yourself another.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Prince_0912
          wrote on 20 Jun 2018, 10:26 last edited by
          #4

          Hi @Pranit-Patil
          For HTTP in Qt there is QtNetwork module. for that you have to inlcude
          QT += network in .pro file.

          after this you can add
          #include <QtNetwork> in your file.

          Then you can use functionalities of QtNetwork.

          Hierarchy of this is,

          QNetworkRequest request(QUrl(“http://example.com/exampleapi”));

          request.setHeader(QNetworkRequest::ContentTypeHeader, “application/xyz”);

          QNetworkAccessManager nam;

          QNetworkReply *reply = nam.post(request, QByteArray &data);

          while(!reply->isFinished())
          {
          qApp->processEvents();
          }
          QByteArray response_data = reply->readAll();

          reply->deleteLater();

          1 Reply Last reply
          3
          • P Offline
            P Offline
            Prince_0912
            wrote on 20 Jun 2018, 10:31 last edited by Prince_0912
            #5

            For set header you can,

            • void QNetworkRequest::setRawHeader(const QByteArray & headerName, const QByteArray & headerValue);

            Sets the value of the known header header to be value, overriding any previously set headers.

            • void QNetworkRequest::setRawHeader(const QByteArray & headerName, const QByteArray & headerValue)

            Sets the header headerName to be of value headerValue. If headerName corresponds to a known header (see QNetworkRequest::KnownHeaders), the raw format will be parsed and the corresponding "cooked" header will be set as well.

            for example:
            request.setRawHeader(QByteArray("Last-Modified"), QByteArray("Sun, 06 Nov 1994 08:49:37 GMT"));

            P 2 Replies Last reply 20 Jun 2018, 10:42
            0
            • P Offline
              P Offline
              Pranit Patil
              wrote on 20 Jun 2018, 10:32 last edited by
              #6

              I am trying following code but not getting error like-
              qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
              qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
              qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
              qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error

              void MainWindow::on_pushButton_clicked()
              {
              QNetworkAccessManager * mgr = new QNetworkAccessManager(this); connect(mgr,SIGNAL(finished(QNetworkReply*)),this,SLOT(onfinish(QNetworkReply*)));
              connect(mgr,SIGNAL(finished(QNetworkReply*)),mgr,SLOT(deleteLater()));

              QByteArray postData =(" user_token":{"Ej14qoqnm9PxZJWXXHPIzX8L2owzQuIPHA0QewilGs8fzScwp6XoPnsQ4KUb71iv","qr_code":"}");
              QUrl serviceURL("https://dev.datoms.io/api/trade/initialization/create_device"); QNetworkRequest request(serviceURL);
              request.setRawHeader("Post", "/api/trade/initialization/create_device HTTP/1.1"); request.setRawHeader("Host:", "dev.datoms.io");
              request.setRawHeader("Cache-Control:","no-cache ");
              mgr->post(request, postData);
              }
              void MainWindow::onfinish(QNetworkReply *rep)
              {
              QByteArray bts = rep->readAll();
              ui->textBrowser->insertPlainText(bts);
              }

              @Embedded Software Developer
              God has given you one face, and you make yourself another.

              1 Reply Last reply
              0
              • P Prince_0912
                20 Jun 2018, 10:31

                For set header you can,

                • void QNetworkRequest::setRawHeader(const QByteArray & headerName, const QByteArray & headerValue);

                Sets the value of the known header header to be value, overriding any previously set headers.

                • void QNetworkRequest::setRawHeader(const QByteArray & headerName, const QByteArray & headerValue)

                Sets the header headerName to be of value headerValue. If headerName corresponds to a known header (see QNetworkRequest::KnownHeaders), the raw format will be parsed and the corresponding "cooked" header will be set as well.

                for example:
                request.setRawHeader(QByteArray("Last-Modified"), QByteArray("Sun, 06 Nov 1994 08:49:37 GMT"));

                P Offline
                P Offline
                Pranit Patil
                wrote on 20 Jun 2018, 10:42 last edited by
                #7

                @Prince_0912 thanks for quick response .
                i will try to implement

                @Embedded Software Developer
                God has given you one face, and you make yourself another.

                1 Reply Last reply
                0
                • P Prince_0912
                  20 Jun 2018, 10:31

                  For set header you can,

                  • void QNetworkRequest::setRawHeader(const QByteArray & headerName, const QByteArray & headerValue);

                  Sets the value of the known header header to be value, overriding any previously set headers.

                  • void QNetworkRequest::setRawHeader(const QByteArray & headerName, const QByteArray & headerValue)

                  Sets the header headerName to be of value headerValue. If headerName corresponds to a known header (see QNetworkRequest::KnownHeaders), the raw format will be parsed and the corresponding "cooked" header will be set as well.

                  for example:
                  request.setRawHeader(QByteArray("Last-Modified"), QByteArray("Sun, 06 Nov 1994 08:49:37 GMT"));

                  P Offline
                  P Offline
                  Pranit Patil
                  wrote on 20 Jun 2018, 10:55 last edited by
                  #8

                  @Prince_0912
                  simply i implement
                  in .cpp file
                  void MainWindow::on_pushButton_clicked()
                  {
                  QNetworkRequest request(QUrl("https://dev.datoms.io/api/trade/initialization/create_device"));

                  //request.setHeader(QNetworkRequest::ContentTypeHeader, "application/xyz");
                  
                  QNetworkAccessManager manager;
                  QByteArray data =("user_token\":{\"Ej14qoqnm9PxZJWXXHPIzX8L2owzQuIPHA0QewilGs8fzScwp6XoPnsQ4KUb71iv\",\"qr_code\":\"QGt0Z9Q5J\",\"circuit_version\":\"1.0.0\",\"device_type\":1\"}");
                  
                  QNetworkReply *reply = manager.post(request, data);
                  
                  while(!reply->isFinished())
                  {
                  qApp->processEvents();
                  }
                  QByteArray response_data = reply->readAll();
                  
                  reply->deleteLater();
                  

                  }

                  application Builded but not geeting any response from server
                  i got this errors
                  qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
                  qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_new
                  qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
                  qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
                  qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error

                  @Embedded Software Developer
                  God has given you one face, and you make yourself another.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Prince_0912
                    wrote on 20 Jun 2018, 11:15 last edited by
                    #9

                    Hi @Pranit-Patil ,

                    These error you can solve by this link .

                    OR

                    You can refer this link for implementing in another.

                    1 Reply Last reply
                    3
                    • P Offline
                      P Offline
                      Pranit Patil
                      wrote on 20 Jun 2018, 14:25 last edited by
                      #10

                      i m getting this type of issues-
                      qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
                      qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_new
                      qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
                      qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
                      qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
                      "Unable to init SSL Context:

                      i already installed OpenSSL 1.0.2e (32bit) but again same problem faced
                      anyone knows help me

                      Thank You.

                      @Embedded Software Developer
                      God has given you one face, and you make yourself another.

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        Pranit Patil
                        wrote on 21 Jun 2018, 06:12 last edited by
                        #11

                        At last, I found the solution. click on following link and download latest version of Win32 OpenSSL v1.1.0h note:Dont download light version ,download 30 MB file

                        http://slproweb.com/products/Win32OpenSSL.html

                        after installing OpenSSL opy the following three dll's in the the directory containing your binary file/Debug folder where your .exe file present.

                        • libeay32.dll
                        • libssl32.dll
                        • ssleay32.dll

                        I solved my problem this one

                        @Embedded Software Developer
                        God has given you one face, and you make yourself another.

                        1 Reply Last reply
                        1
                        • P Offline
                          P Offline
                          Prince_0912
                          wrote on 21 Jun 2018, 07:41 last edited by
                          #12

                          Ok finally you got solution. Now make this Topic to Mark as Solved.
                          Go to right hand side of page -> click on Topic Tools -> Mark as Solved.
                          Thank you.

                          P 1 Reply Last reply 21 Jun 2018, 09:08
                          0
                          • P Prince_0912
                            21 Jun 2018, 07:41

                            Ok finally you got solution. Now make this Topic to Mark as Solved.
                            Go to right hand side of page -> click on Topic Tools -> Mark as Solved.
                            Thank you.

                            P Offline
                            P Offline
                            Pranit Patil
                            wrote on 21 Jun 2018, 09:08 last edited by
                            #13

                            @Prince_0912 Thank you for your guidlines

                            @Embedded Software Developer
                            God has given you one face, and you make yourself another.

                            1 Reply Last reply
                            1

                            4/13

                            20 Jun 2018, 10:26

                            9 unread
                            • Login

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