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
QtWS25 Last Chance

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.
  • Pranit PatilP Offline
    Pranit PatilP Offline
    Pranit Patil
    wrote on 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.

    jazzycamelJ 1 Reply Last reply
    0
    • Pranit PatilP Pranit Patil

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

      jazzycamelJ Offline
      jazzycamelJ Offline
      jazzycamel
      wrote on 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
      • Pranit PatilP Offline
        Pranit PatilP Offline
        Pranit Patil
        wrote on 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
        • Prince_0912P Offline
          Prince_0912P Offline
          Prince_0912
          wrote on 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
          • Prince_0912P Offline
            Prince_0912P Offline
            Prince_0912
            wrote on 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"));

            Pranit PatilP 2 Replies Last reply
            0
            • Pranit PatilP Offline
              Pranit PatilP Offline
              Pranit Patil
              wrote on 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
              • Prince_0912P Prince_0912

                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"));

                Pranit PatilP Offline
                Pranit PatilP Offline
                Pranit Patil
                wrote on 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
                • Prince_0912P Prince_0912

                  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"));

                  Pranit PatilP Offline
                  Pranit PatilP Offline
                  Pranit Patil
                  wrote on 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
                  • Prince_0912P Offline
                    Prince_0912P Offline
                    Prince_0912
                    wrote on 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
                    • Pranit PatilP Offline
                      Pranit PatilP Offline
                      Pranit Patil
                      wrote on 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
                      • Pranit PatilP Offline
                        Pranit PatilP Offline
                        Pranit Patil
                        wrote on 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
                        • Prince_0912P Offline
                          Prince_0912P Offline
                          Prince_0912
                          wrote on 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.

                          Pranit PatilP 1 Reply Last reply
                          0
                          • Prince_0912P Prince_0912

                            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.

                            Pranit PatilP Offline
                            Pranit PatilP Offline
                            Pranit Patil
                            wrote on 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

                            • Login

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