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.7k 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.
  • A Axel Spoerl
    30 Jun 2022, 05:43

    403 is what your server sends. It means that your parameters are incorrect or the server itself has (due to misconfiguration) no access to the requested resource.
    Have you tried the call with postman or a browser?

    A Offline
    A Offline
    ali-aydin
    wrote on 30 Jun 2022, 08:05 last edited by
    #16

    @Axel-Spoerl
    Yes I tried by postman and is ok

    J 1 Reply Last reply 30 Jun 2022, 09:10
    0
    • A ali-aydin
      30 Jun 2022, 08:05

      @Axel-Spoerl
      Yes I tried by postman and is ok

      J Offline
      J Offline
      JonB
      wrote on 30 Jun 2022, 09:10 last edited by
      #17

      @ali-aydin
      Your platform/web server may/should have the ability to log all requests/responses to a log file? You might switch that on and see if anything helpful there?

      A 1 Reply Last reply 30 Jun 2022, 09:40
      0
      • J JonB
        30 Jun 2022, 09:10

        @ali-aydin
        Your platform/web server may/should have the ability to log all requests/responses to a log file? You might switch that on and see if anything helpful there?

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

        @JonB
        OS is Windows 10 and qt 5.15.2

        J 1 Reply Last reply 30 Jun 2022, 09:46
        0
        • A ali-aydin
          30 Jun 2022, 09:40

          @JonB
          OS is Windows 10 and qt 5.15.2

          J Offline
          J Offline
          JonB
          wrote on 30 Jun 2022, 09:46 last edited by
          #19

          @ali-aydin Look in your web server's documentation.

          A 1 Reply Last reply 30 Jun 2022, 11:39
          0
          • J JonB
            30 Jun 2022, 09:46

            @ali-aydin Look in your web server's documentation.

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

            @JonB
            API's documentation?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mchinand
              wrote on 30 Jun 2022, 12:50 last edited by
              #21

              I think you have to add 'Basic ' before your token when you set the Authorization header (or 'Bearer ' if you are doing bearer token auth). If things are working in Postman, check the 'Headers' tab of your request as to what is the actual value being sent for the Authorization.

              A 1 Reply Last reply 30 Jun 2022, 13:59
              0
              • M mchinand
                30 Jun 2022, 12:50

                I think you have to add 'Basic ' before your token when you set the Authorization header (or 'Bearer ' if you are doing bearer token auth). If things are working in Postman, check the 'Headers' tab of your request as to what is the actual value being sent for the Authorization.

                A Offline
                A Offline
                ali-aydin
                wrote on 30 Jun 2022, 13:59 last edited by ali-aydin
                #22

                @mchinand
                Bearer must be added to the token.
                in postman there is no header
                in authorization tab
                only added token and in parameters tab is only one parameter :KalaCode
                in body tab username,password and grant_type
                in the qt when I want to authenticate by

                QUrl url("http://localhost:594444/api/authenticate");
                

                it returns "Hello"
                but when i changing url to

                QUrl url("http://localhost:594444/api/Getmojodi" );
                

                it does not work

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

                  I meant the 'Headers' tab of the Postman request:
                  b0973db6-0abc-4a60-9d8e-5e0955d007f9-image.png

                  The authorization header value above was automatically set when I added a (junk) username and password in the Auth tab:

                  a33e651c-8868-47c3-b96e-f7569e008cc0-image.png

                  A 1 Reply Last reply 30 Jun 2022, 14:17
                  0
                  • M mchinand
                    30 Jun 2022, 14:05

                    I meant the 'Headers' tab of the Postman request:
                    b0973db6-0abc-4a60-9d8e-5e0955d007f9-image.png

                    The authorization header value above was automatically set when I added a (junk) username and password in the Auth tab:

                    a33e651c-8868-47c3-b96e-f7569e008cc0-image.png

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

                    @mchinand
                    there is no problem in postman
                    problem is that how can we do authorization in qt?
                    i think yhe main problem is this

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

                      Are you setting the Authorization the same in Qt as the value it is set in Postman? Your variables are 'basic_authorization' and 'token', is token just the token or is the token type prepended to it ('Basic ' or 'Bearer ')? Your variable is 'basic_authorization' but in your prior message, you mention adding 'Bearer' before the token, which auth method are you using?

                      A 1 Reply Last reply 30 Jun 2022, 14:35
                      0
                      • M mchinand
                        30 Jun 2022, 14:24

                        Are you setting the Authorization the same in Qt as the value it is set in Postman? Your variables are 'basic_authorization' and 'token', is token just the token or is the token type prepended to it ('Basic ' or 'Bearer ')? Your variable is 'basic_authorization' but in your prior message, you mention adding 'Bearer' before the token, which auth method are you using?

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

                        @mchinand
                        i'm using url.setRawHeader() for add token to url and
                        and adding bearer to token
                        i don't use any auth method
                        how to use that?

                        M 1 Reply Last reply 30 Jun 2022, 14:45
                        0
                        • A ali-aydin
                          30 Jun 2022, 14:35

                          @mchinand
                          i'm using url.setRawHeader() for add token to url and
                          and adding bearer to token
                          i don't use any auth method
                          how to use that?

                          M Offline
                          M Offline
                          mchinand
                          wrote on 30 Jun 2022, 14:45 last edited by
                          #27

                          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 1 Reply Last reply 30 Jun 2022, 14:52
                          0
                          • 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

                                          25/40

                                          30 Jun 2022, 14:24

                                          • Login

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