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. Accessing Https, host requires authentication message
QtWS25 Last Chance

Accessing Https, host requires authentication message

Scheduled Pinned Locked Moved General and Desktop
httpsqnetworkreplyauthentication
18 Posts 2 Posters 14.7k 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.
  • R Offline
    R Offline
    roseicollis
    wrote on 29 Apr 2015, 15:21 last edited by
    #1

    Hi,

    I have a GUI app (Qt 4.8.5) which loads info on a combobox depending on the JSon info obtained by webservice, which works fine. The code is something like:

    _Url = "http://www.myweb.com/paramlist_whith_user_and_password";
    QNetworkRequest request(_Url);
    QNetworkReply *myReply = nam->get(request);
    

    The thing is that now this web is not http but https, so I do the same adding this 's' but then my combobox is empty and if I print that:

    qDebug() << " reply: " << myReply->errorString();
    

    what I get is: "Host requires authentication"

    Any idea of what do I need to do, add or change to solve this? I tried putting before something like:

    on constructor:
     connect(nam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
                SLOT(provideAuthenication(QNetworkReply*,QAuthenticator*)));
    
    void mywp::provideAuthenication(QNetworkReply *reply, QAuthenticator *ator)
    {
       ator->setUser(QString("USERNAME"));
       ator->setPassword(QString("MYPASSWORD"));
    }
    

    But it doesn't work...

    Thank you so much.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 29 Apr 2015, 22:29 last edited by
      #2

      Hi,

      What kind of authentication is your web service using ?

      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
      • R Offline
        R Offline
        roseicollis
        wrote on 30 Apr 2015, 06:55 last edited by
        #3

        Hi Sgaist,

        What do you mean? Sorry but i didn't do the web service (its a workmate who do it and they just told me to change http to https but ofc it requires more things as I see). The thing is that in the params I pass I gave there the user, the password and a couple of things more and so the web take that to know if I can connect or not.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 30 Apr 2015, 22:55 last edited by
          #4

          You can have no authentication to talk with the entry point for your web service or you can have Basic Auth, Token, OAuth etc.

          Check with your colleague if he implemented anything 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

          R 1 Reply Last reply 5 May 2015, 07:30
          0
          • S SGaist
            30 Apr 2015, 22:55

            You can have no authentication to talk with the entry point for your web service or you can have Basic Auth, Token, OAuth etc.

            Check with your colleague if he implemented anything like that

            R Offline
            R Offline
            roseicollis
            wrote on 5 May 2015, 07:30 last edited by roseicollis 5 May 2015, 07:42
            #5

            @SGaist Hi, I asked about it and my workmate told me that we use cookies and that maybe its something like the Token you said. To understand better the behaviour: in every request I do to the webservice I have to send the username and password so each time it 'logs in'

            May it be because the webservice returns a 204 (which is a 'Ok but I have nothing for you') and the Qt interprets it as it is not ok??

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 5 May 2015, 23:30 last edited by
              #6

              Wait, then what do you mean it doesn't work ? If you get 204 it means that you succeeded but you won't receive any data.

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

              R 1 Reply Last reply 6 May 2015, 07:19
              0
              • S SGaist
                5 May 2015, 23:30

                Wait, then what do you mean it doesn't work ? If you get 204 it means that you succeeded but you won't receive any data.

                R Offline
                R Offline
                roseicollis
                wrote on 6 May 2015, 07:19 last edited by
                #7

                Hi. Sorry I was not sure if was a 204. My workmate told me that maybe this was the cause but then I tried something: If I put the url where I do the request on firefox for example, it is ok and it returns the json list so I suppose that it is not a 204. But this url in my code returns what I said about Host requires authentication and I suppose that its something I'm doing wrong with my code and Qt.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 6 May 2015, 21:51 last edited by
                  #8

                  Can you show how you are doing these requests ?

                  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
                  • R Offline
                    R Offline
                    roseicollis
                    wrote on 13 May 2015, 08:14 last edited by roseicollis
                    #9

                    Hi Sgaist,

                    Sorry for answering so late but I was outside. The request more specifically is this:

                    _Url= "https://myweb.com/Ob/places?INFO1=ABCDEF&password=012345&username=Mario";
                    QNetworkRequest request(_Url);
                    QNetworkReply *myReply = nam->get(request);
                    

                    I don't do any other thing...

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 13 May 2015, 22:58 last edited by SGaist
                      #10

                      It's not how you should do the request, search for "basic http authentication" and QNetworkAccessManager::authenticationRequired

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

                      R 1 Reply Last reply 15 May 2015, 07:22
                      0
                      • S SGaist
                        13 May 2015, 22:58

                        It's not how you should do the request, search for "basic http authentication" and QNetworkAccessManager::authenticationRequired

                        R Offline
                        R Offline
                        roseicollis
                        wrote on 15 May 2015, 07:22 last edited by
                        #11

                        @SGaist oh sorry!! I think you mean this:
                        I tried with:

                        Constructor:

                        nam = new QNetworkAccessManager(this);
                        QObject::connect ( nam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(onAuthenticationRequestSlot(QNetworkReply*,QAuthenticator*)) );
                        
                        

                        And then this, but it never gets into here...

                        void WPConfigs12::onAuthenticationRequestSlot(QNetworkReply *aReply, QAuthenticator *aAuthenticator)
                        {
                             qDebug() << "INSIDE ";
                            aAuthenticator->setUser("Mario");
                            aAuthenticator->setPassword("012345");
                        }
                        
                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 16 May 2015, 20:43 last edited by
                          #12

                          You really should get more details from your colleague on how what he uses to handle user authentication

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

                          R 1 Reply Last reply 18 May 2015, 07:53
                          0
                          • S SGaist
                            16 May 2015, 20:43

                            You really should get more details from your colleague on how what he uses to handle user authentication

                            R Offline
                            R Offline
                            roseicollis
                            wrote on 18 May 2015, 07:53 last edited by roseicollis
                            #13

                            @SGaist Is it normal that the "INSIDE" qDebug message is not pritned? I mean... its like the connect doesn't work and maybe its because i did it wrong... (last time this happened to me was because I was working with threads and I forgot to start it so the connect failed.)

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 19 May 2015, 23:26 last edited by
                              #14

                              Your connect statement looks fine. Do you have any error message on the console ?

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

                              R 1 Reply Last reply 22 May 2015, 07:26
                              0
                              • S SGaist
                                19 May 2015, 23:26

                                Your connect statement looks fine. Do you have any error message on the console ?

                                R Offline
                                R Offline
                                roseicollis
                                wrote on 22 May 2015, 07:26 last edited by
                                #15

                                @SGaist No, nothing...In the compile output there is nothing wrong. I just had QLayout: Attempting to add QLayout "" to WizardPage2"WizardPage2", which already has a layout in Applicatiion output but this does not affect the program... and the connect itsself has anything it need to work because I have others that run with no problem. (Have what it needs = Q_OBJECT declared in header and so on).
                                That's why I asked if maybe I needed to start anything as it was a thread (If you work with threads and don't start them, you have the same problem)

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 22 May 2015, 21:55 last edited by
                                  #16

                                  Unless you put your QNAM in a thread, no theres nothing special you need to do.
                                  As a last restort, you can set the Authorization header yourself on the query

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

                                  R 1 Reply Last reply 26 May 2015, 11:31
                                  0
                                  • S SGaist
                                    22 May 2015, 21:55

                                    Unless you put your QNAM in a thread, no theres nothing special you need to do.
                                    As a last restort, you can set the Authorization header yourself on the query

                                    R Offline
                                    R Offline
                                    roseicollis
                                    wrote on 26 May 2015, 11:31 last edited by
                                    #17

                                    @SGaist THats so strange.... I hate when something seems to work fine but doesnt.. hehe
                                    How do you set it with the query?

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 27 May 2015, 06:59 last edited by
                                      #18

                                      Use setRawHeader from QNetworkRequest with Authorization as the name

                                      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

                                      10/18

                                      13 May 2015, 22:58

                                      • Login

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