[SOLVED] QWebview - website requires authentication
Hi,
I am developing an application that uses the ‘QWebview’ widget to display a website on the internet.
My problem is, the website I am trying to load has a authentication popup window (as soon as you load the page) so you can enter a username and password – but when using the Webview widget, it just displays the following error message:
“Authorization Required. This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn’t understand how to supply the credentials required”.
Is there a way round this?
My code:
10 replies
What about QNetworkAccessManager?
Trying to get this method to work but I am getting no such SLOT errors!
- connect(manager,SIGNAL(authenticationRequired(QNetworkReply reply*, QAuthenticator auth*)),SLOT(provideAuthentication(QNetworkReply *reply,QAuthenticator *auth)));
- {
- auth->setUser("username");
- auth->setPassword("password");
- }
Try this:
- connect(manager,SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),SLOT(provideAuthentication(QNetworkReply*,QAuthenticator*)));
You know what it will only work for HTTP-Basic authentication? If website has login form, it is mostly POST or GET request needed.
Still getting error message with what you advised to try:
Object::connect: No such slot MainWindow::provideAuthentication(QNetworkReply*,QAuthenticator*) in mainwindow.cpp
Object::connect: (receiver name: ‘MainWindow’)
I have declared this is the mainwindow.h file under “public slots:”
Actually, it doesn’t have to “automatically” log into the website, even if I can just get it to display the login form so I can manually enter the username and password?
You have a problem with the signal/slot code, not with QNetworkManager. Have a look at http://doc.qt.nokia.com/4.7-snapshot/signalsandslots.html . Before this debug message is resolved, there is no use in continuing.
I am revisiting this problem after several months of doing another project.
I tried the https log on above but it still didn’t work. Actually, you can’t even log in to the website through a normal browser by using the https:// address.
It is a pitty that the website doesn’t support puting the username and password into the address field (i.e http://username:password@webaddress.com) because that would solve my problems!
Try this:You know what it will only work for HTTP-Basic authentication? If website has login form, it is mostly POST or GET request needed.
QNetworkAccessManager *manager = new QNetworkAccessManager(); connect(manager,SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),SLOT(provideAuthentication(QNetworkReply*,QAuthenticator*)));
Once I got the slots working, this way worked!
Hi,[…]
My code:
m_pWebView->url().setUserName("username"); m_pWebView->url().setPassword("password"); m_pWebView->show();
Err, this cannot work. You set username and password on the view’s URL just to load a fresh QUrl object which has no username and password set.
Just to be clear: setUserName and setPassword belong to QUrl but not to QWebView, hence the values you specify in line 2 and 3 are set on the currently loaded QUrl object. As soon as you load another QUrl object (line 5) the old one is thrown away and username & password of the new QUrl object are used, which might not be set or are set up with incorrect values.
Setup url first, then load in your view. There you go:
Good stuff. Yeah this way would work for websites that require authentication through the web url.
In my case, it was a form that pops up that you have to manually enter the username and password (does not work by puting the username:password in address bar).
I had to use QNetworkManager with provideAuthenticationSlot to get my way to work.
You must log in to post a reply. Not a member yet? Register here!





