Accessing Https, host requires authentication message
-
Hi,
What kind of authentication is your web service using ?
-
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.
-
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
-
@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??
-
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.
-
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.
-
Can you show how you are doing these requests ?
-
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...
-
It's not how you should do the request, search for "basic http authentication" and QNetworkAccessManager::authenticationRequired
-
@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"); }
-
You really should get more details from your colleague on how what he uses to handle user authentication
-
@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.)
-
Your connect statement looks fine. Do you have any error message on the console ?
-
@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) -
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 -
Use setRawHeader from QNetworkRequest with Authorization as the name