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. Sending parameters by get method to rest api
Forum Updated to NodeBB v4.3 + New Features

Sending parameters by get method to rest api

Scheduled Pinned Locked Moved Solved General and Desktop
40 Posts 5 Posters 5.3k Views 2 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.
  • M mchinand
    30 Jun 2022, 14:45

    Are you doing Basic (username/password) or Bearer Token? What method are you selecting in Postman? What is the value of your token variable, post the string but modify the actual token part.

    A Offline
    A Offline
    ali-aydin
    wrote on 30 Jun 2022, 14:52 last edited by
    #28

    @mchinand
    in postman i selected bearer method
    and token has three part access_ token,token_type and expire_date
    in qt i added "bearer" to access_token then adding this token to url.setRawHeader()

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on 30 Jun 2022, 14:55 last edited by
      #29

      What is the value of your token variable, post the string but modify the actual token part.

      A 1 Reply Last reply 30 Jun 2022, 15:10
      0
      • M mchinand
        30 Jun 2022, 14:55

        What is the value of your token variable, post the string but modify the actual token part.

        A Offline
        A Offline
        ali-aydin
        wrote on 30 Jun 2022, 15:10 last edited by ali-aydin
        #30

        @mchinand
        this is token file

        {
           "access_token": "1zVIXlpahfvS82xJEN2l2L7vPaUvX-AqHD5w_JmrSqHtV_hHdk6dKqdyFx6D62p1jPIcPPMdlVlsOlS4ZcoVUcsnrzTv8Ly42OLINofJYfdkVoitAQGdCzX7vYlnWBYNrxAOsMJiCdbjvONC2MftONA_hxhcsf8D3ax24buIupEkqPUoaBWUd6nx7HTx3Axo8ZdHZhM48SS68CczY-EDVUTDQSvYxv_4gQCxf_uWPuTrjTF2jwCbLfrCmhK7O_WJ07XmV-PYTj2jV7E35CpeFtx6W_FePFlhzim9qLv",
           "token_type": "bearer",
           "expires_in": 86399
        }
        
        1 Reply Last reply
        0
        • M Offline
          M Offline
          mchinand
          wrote on 30 Jun 2022, 15:27 last edited by
          #31

          Try

          QString token = <access_token from file>
          token.prepend("Bearer ");
          req1.setRawHeader(QByteArrayLiteral("Authorization"), token.toUtf8());
          

          I don't think you want the 'toBase64()' that you have in your code above.

          A 1 Reply Last reply 30 Jun 2022, 17:43
          0
          • M mchinand
            30 Jun 2022, 15:27

            Try

            QString token = <access_token from file>
            token.prepend("Bearer ");
            req1.setRawHeader(QByteArrayLiteral("Authorization"), token.toUtf8());
            

            I don't think you want the 'toBase64()' that you have in your code above.

            A Offline
            A Offline
            ali-aydin
            wrote on 30 Jun 2022, 17:43 last edited by
            #32

            @mchinand
            nop it is not ok

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 30 Jun 2022, 17:45 last edited by
              #33

              Check the request sent by postman and the one from your application and compare for differences.

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

              A 1 Reply Last reply 30 Jun 2022, 18:11
              1
              • S SGaist
                30 Jun 2022, 17:45

                Check the request sent by postman and the one from your application and compare for differences.

                A Offline
                A Offline
                ali-aydin
                wrote on 30 Jun 2022, 18:11 last edited by
                #34

                @SGaist
                yes good idea

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mchinand
                  wrote on 30 Jun 2022, 18:53 last edited by
                  #35

                  Be sure to compare the url, body, and header (also, be sure to look at the auto-generated headers in Postman which are hidden by default). Are you extracting the token correctly from your file? Have you debugged that part of your code? You did not include that with your original post.

                  A 2 Replies Last reply 1 Jul 2022, 10:48
                  0
                  • M mchinand
                    30 Jun 2022, 18:53

                    Be sure to compare the url, body, and header (also, be sure to look at the auto-generated headers in Postman which are hidden by default). Are you extracting the token correctly from your file? Have you debugged that part of your code? You did not include that with your original post.

                    A Offline
                    A Offline
                    ali-aydin
                    wrote on 1 Jul 2022, 10:48 last edited by ali-aydin 7 Jan 2022, 10:58
                    #36

                    @mchinand
                    error body is :
                    Error transferring http://localhost:59444/api/Getmojodi?KalaCode=20101010131310 - server replied: Forbidden
                    and ststus code is :403
                    and hidden headers in postman :
                    Untitled21.png

                    1 Reply Last reply
                    0
                    • M mchinand
                      30 Jun 2022, 18:53

                      Be sure to compare the url, body, and header (also, be sure to look at the auto-generated headers in Postman which are hidden by default). Are you extracting the token correctly from your file? Have you debugged that part of your code? You did not include that with your original post.

                      A Offline
                      A Offline
                      ali-aydin
                      wrote on 1 Jul 2022, 11:50 last edited by ali-aydin 7 Jan 2022, 11:52
                      #37

                      @mchinand
                      @JonB
                      @SGaist
                      @Axel-Spoerl
                      Thank you everyone without your help I could not resolve that.
                      Thank you so much

                      A 1 Reply Last reply 1 Jul 2022, 11:54
                      0
                      • A ali-aydin
                        1 Jul 2022, 11:50

                        @mchinand
                        @JonB
                        @SGaist
                        @Axel-Spoerl
                        Thank you everyone without your help I could not resolve that.
                        Thank you so much

                        A Offline
                        A Offline
                        ali-aydin
                        wrote on 1 Jul 2022, 11:54 last edited by
                        #38

                        @ali-aydin
                        this problem solution :
                        request must be in this shape :

                        QUrl url("http://localhost:59444/api/Getmojodi");
                            
                            request.setRawHeader(QByteArrayLiteral("Authorization"),token.toUtf8());
                            request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
                            request.setRawHeader(QByteArrayLiteral("User-Agent"),"ApiTest2/1.0");
                            request.setRawHeader(QByteArrayLiteral("Accept"),"*/*");
                            request.setRawHeader(QByteArrayLiteral("Accept-Encoding"),"gzip, deflate, br");
                            request.setRawHeader(QByteArrayLiteral("Connection"),"keep-alive");
                            request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
                            QUrlQuery uq;
                            uq.addQueryItem("KalaCode","20101010131310");
                            url.setQuery(uq);
                            request.setUrl(url);
                            manager->get(request);
                        
                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 1 Jul 2022, 18:10 last edited by
                          #39

                          The user agent is likely not needed in your case.

                          I think that you essentially need Content-Type and Accept-Encoding beside Authorization.

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

                          A 1 Reply Last reply 1 Jul 2022, 19:55
                          0
                          • S SGaist
                            1 Jul 2022, 18:10

                            The user agent is likely not needed in your case.

                            I think that you essentially need Content-Type and Accept-Encoding beside Authorization.

                            A Offline
                            A Offline
                            ali-aydin
                            wrote on 1 Jul 2022, 19:55 last edited by
                            #40

                            @SGaist
                            Thank you I will check it

                            1 Reply Last reply
                            0

                            37/40

                            1 Jul 2022, 11:50

                            • Login

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