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. POST request from curl example
Forum Updated to NodeBB v4.3 + New Features

POST request from curl example

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 1.9k 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.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by
    #1

    Hi,
    I got example the request like below:

    curl --request POST \
      --url https://demo1.vnetlpr.pl/api/events/search \
      --header 'Accept: application/json' \
      --header 'Content-Type: application/x-www-form-urlencoded' \
      --data public_key=01932182-8a75-7238-9b04-e969bcb9e9e6 \
      --data 'hash=MD5( public_key + private_key )' \
    

    do I prepared the same code like above but in in qt ?

    QNetworkRequest request;
    request.setUrl(QUrl("https://demo1.vnetlpr.pl/api/events/search"));
    request.setRawHeader("Accept", "application/json");
    request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
    
    QJsonObject obj;
    obj["public_key"] = (QString)publicKey;
    obj["hash"]= (QString)QCryptographicHash::hash(publicKey + privateKey, QCryptographicHash::Md5);
    
    QNetworkReply *reply = manager.post(request, QJsonDocument(obj).toJson());
    
    SGaistS 1 Reply Last reply
    0
    • D Offline
      D Offline
      Damian7546
      wrote on last edited by Damian7546
      #4

      You're right. The request body it doesn't in JSON notation.

      I rewrote my code like below:

      QNetworkRequest request;
      request.setUrl(QUrl("https://demo1.vcn.pl/api/events/search"));
      request.setRawHeader("Accept", "application/json");
      request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
      
      QByteArray md5 = QCryptographicHash::hash(publicKey + privateKey, QCryptographicHash::Md5);
      auto ba = QByteArray("public_key="+publicKey+"&hash="+md5);
      
      QNetworkReply *reply = manager.post(request,ba);
      
      

      Now is the same what in example in the first post ?

      1 Reply Last reply
      0
      • hskoglundH Offline
        hskoglundH Offline
        hskoglund
        wrote on last edited by
        #2

        Hi, the .setRawHeader()s look ok but QJson? I don't see any colons etc. in the curl example, the --data lines seem to be vanilla params, so try something like:

        auto ba = QByteArray("public_key=01932182-8a75-7238-9b04-e969bcb9e9e6&hash=MD5( public_key + private_key )");
        QNetworkReply *reply = manager.post(request, ba);
        
        1 Reply Last reply
        1
        • D Damian7546

          Hi,
          I got example the request like below:

          curl --request POST \
            --url https://demo1.vnetlpr.pl/api/events/search \
            --header 'Accept: application/json' \
            --header 'Content-Type: application/x-www-form-urlencoded' \
            --data public_key=01932182-8a75-7238-9b04-e969bcb9e9e6 \
            --data 'hash=MD5( public_key + private_key )' \
          

          do I prepared the same code like above but in in qt ?

          QNetworkRequest request;
          request.setUrl(QUrl("https://demo1.vnetlpr.pl/api/events/search"));
          request.setRawHeader("Accept", "application/json");
          request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
          
          QJsonObject obj;
          obj["public_key"] = (QString)publicKey;
          obj["hash"]= (QString)QCryptographicHash::hash(publicKey + privateKey, QCryptographicHash::Md5);
          
          QNetworkReply *reply = manager.post(request, QJsonDocument(obj).toJson());
          
          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by SGaist
          #3

          Hi,

          @Damian7546 said in POST request from curl example:

          obj["public_key"] = (QString)publicKey;
          obj["hash"]= (QString)QCryptographicHash::hash(publicKey + privateKey, QCryptographicHash::Md5);

          Beside the good points made by @hskoglund, this is pretty wrong. You can't type cast a QByteArray as a QString like that.

          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
          1
          • D Offline
            D Offline
            Damian7546
            wrote on last edited by Damian7546
            #4

            You're right. The request body it doesn't in JSON notation.

            I rewrote my code like below:

            QNetworkRequest request;
            request.setUrl(QUrl("https://demo1.vcn.pl/api/events/search"));
            request.setRawHeader("Accept", "application/json");
            request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
            
            QByteArray md5 = QCryptographicHash::hash(publicKey + privateKey, QCryptographicHash::Md5);
            auto ba = QByteArray("public_key="+publicKey+"&hash="+md5);
            
            QNetworkReply *reply = manager.post(request,ba);
            
            

            Now is the same what in example in the first post ?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Damian7546
              wrote on last edited by Damian7546
              #5
              This post is deleted!
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                Did you check the server logs ?
                Did you connect the reply errorOccured and sslErrors signals ?

                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
                • D Damian7546 has marked this topic as solved on
                • D Offline
                  D Offline
                  Damian7546
                  wrote on last edited by
                  #7

                  @SGaist working! Tahnks for help.

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

                    What did you do to fix the problem ?

                    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
                    • D Offline
                      D Offline
                      Damian7546
                      wrote on last edited by Damian7546
                      #9

                      @SGaist In Ubuntu (where I developing my app) I had a problem with ssl, and below solution fixed my problem:
                      https://forum.qt.io/topic/144102/qsslsocket-failure-from-online-installer-version-ubuntu/8

                      And added to *.pro file:

                      LIBS += -L/opt/openssl-1.1.1q -lcrypto 
                      LIBS += -L/opt/openssl-1.1.1q -lssl
                      

                      I have no idea how to run it on my destinatiom machine based on Debian System ....

                      To generate file to my destination machine I use CQtDeployer , which one generate below directories:
                      Bez tytułu.jpg
                      but inside I do not see any files related with ssl.

                      @SGaist What can I do ?

                      SGaistS 1 Reply Last reply
                      0
                      • D Damian7546

                        @SGaist In Ubuntu (where I developing my app) I had a problem with ssl, and below solution fixed my problem:
                        https://forum.qt.io/topic/144102/qsslsocket-failure-from-online-installer-version-ubuntu/8

                        And added to *.pro file:

                        LIBS += -L/opt/openssl-1.1.1q -lcrypto 
                        LIBS += -L/opt/openssl-1.1.1q -lssl
                        

                        I have no idea how to run it on my destinatiom machine based on Debian System ....

                        To generate file to my destination machine I use CQtDeployer , which one generate below directories:
                        Bez tytułu.jpg
                        but inside I do not see any files related with ssl.

                        @SGaist What can I do ?

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @Damian7546 you don't . You have to deploy the libraries along with your application.

                        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
                        0
                        • SGaistS SGaist

                          @Damian7546 you don't . You have to deploy the libraries along with your application.

                          D Offline
                          D Offline
                          Damian7546
                          wrote on last edited by Damian7546
                          #11

                          @SGaist hmm... but I do not know how....

                          JonBJ 1 Reply Last reply
                          0
                          • D Damian7546

                            @SGaist hmm... but I do not know how....

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #12

                            @Damian7546 Start by looking at the alternatives mentioned in https://forum.qt.io/topic/154740/where-is-linuxdeployqt

                            D 1 Reply Last reply
                            0
                            • JonBJ JonB

                              @Damian7546 Start by looking at the alternatives mentioned in https://forum.qt.io/topic/154740/where-is-linuxdeployqt

                              D Offline
                              D Offline
                              Damian7546
                              wrote on last edited by
                              #13

                              @JonB I Use CQtDeployer.
                              I am currently using two options:
                              cqtdeployer -bin -qmlDir
                              To add libs from my .pro file :
                              LIBS += -L/opt/openssl-1.1.1q -lcrypto
                              LIBS += -L/opt/openssl-1.1.1q -lssl

                              Which one options I should add ? -libDir or -extraLibs ?

                              D 1 Reply Last reply
                              0
                              • D Damian7546

                                @JonB I Use CQtDeployer.
                                I am currently using two options:
                                cqtdeployer -bin -qmlDir
                                To add libs from my .pro file :
                                LIBS += -L/opt/openssl-1.1.1q -lcrypto
                                LIBS += -L/opt/openssl-1.1.1q -lssl

                                Which one options I should add ? -libDir or -extraLibs ?

                                D Offline
                                D Offline
                                Damian7546
                                wrote on last edited by Damian7546
                                #14

                                @JonB @SGaist

                                I copied dictionary with ssl library to my qt project location:

                                .../Lib/openssl-1.1.1q

                                And changed the *.pro file to:

                                LIBS += -L$$PWD/Lib/openssl-1.1.1q/ -lcrypto
                                LIBS += -L$$PWD/Lib/openssl-1.1.1q/ -lssl

                                Application works , when is runnig form qt creator . But when I run without qt creator it doesnt work ...

                                JonBJ 1 Reply Last reply
                                0
                                • D Damian7546

                                  @JonB @SGaist

                                  I copied dictionary with ssl library to my qt project location:

                                  .../Lib/openssl-1.1.1q

                                  And changed the *.pro file to:

                                  LIBS += -L$$PWD/Lib/openssl-1.1.1q/ -lcrypto
                                  LIBS += -L$$PWD/Lib/openssl-1.1.1q/ -lssl

                                  Application works , when is runnig form qt creator . But when I run without qt creator it doesnt work ...

                                  JonBJ Online
                                  JonBJ Online
                                  JonB
                                  wrote on last edited by
                                  #15

                                  @Damian7546
                                  Assuming by "doesnt work" you mean you are told it cannot find the OpenSSL shared libraries at runtime.

                                  Then the implication is that the environment/search path is somehow different from Creator than without. E.g. check your LD_LIBRARY_PATH.

                                  From a terminal try running ldd on your executable. Does that show it requiring certain *.so files which cannot be found?

                                  I believe the OpenSSL runtime provides some runtime openssl.so (or whatever name) file(s). Find these.

                                  I copied dictionary with ssl library to my qt project location:

                                  That may be enough for linking, but I don't think it is for locating the .so files at runtime under Linux. Unless they are picked up off the RPATH which was linked into the program.

                                  D 1 Reply Last reply
                                  1
                                  • JonBJ JonB

                                    @Damian7546
                                    Assuming by "doesnt work" you mean you are told it cannot find the OpenSSL shared libraries at runtime.

                                    Then the implication is that the environment/search path is somehow different from Creator than without. E.g. check your LD_LIBRARY_PATH.

                                    From a terminal try running ldd on your executable. Does that show it requiring certain *.so files which cannot be found?

                                    I believe the OpenSSL runtime provides some runtime openssl.so (or whatever name) file(s). Find these.

                                    I copied dictionary with ssl library to my qt project location:

                                    That may be enough for linking, but I don't think it is for locating the .so files at runtime under Linux. Unless they are picked up off the RPATH which was linked into the program.

                                    D Offline
                                    D Offline
                                    Damian7546
                                    wrote on last edited by
                                    #16

                                    @JonB Now work!

                                    I copied from: ..../Lib/openssl-1.1.1q below files:
                                    libcrypto.so
                                    libcrypto.so.1.1
                                    libssl.so
                                    libssl.so.1.1

                                    to my deployed application

                                    It look like by default, an SSL library are dynamically loads any installed OpenSSL library at run-time.

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

                                      Yes, by default Qt builds dlopens OpenSSL.

                                      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
                                      1

                                      • Login

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