PDA

View Full Version : website requires authentication



prajith
4th May 2014, 11:36
I am developing an application that uses the ‘QWebview’ to display the websites on the internet.

My problem is, the website which I am trying to load has a authentication popup window (HTTP BASIC AUTH) so you can enter a username and password, after the authorization, when I try to open a link in new window or tab it is keep asking me the same popup instad of loading the page directly. Here is my Webview subclass.


WebView::WebView(QWidget *parent) : QWebView(parent) {
page()->deleteLater();
QWebPage *newWeb = new QWebPage();

NetworkAccessManager *network = new NetworkAccessManager();
setPage(newWeb);
setRenderHints(QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing | QPainter::Antialiasing);

page()->setForwardUnsupportedContent(true);
page()->setNetworkAccessManager(network);
this->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
this->settings()->setAttribute(QWebSettings::JavaEnabled, true);
this->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
this->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
this->settings()->setAttribute(QWebSettings::LocalStorageDatabaseEna bled, true);
this->settings()->setAttribute(QWebSettings::OfflineWebApplicationCa cheEnabled, true);
this->settings()->setAttribute(QWebSettings::OfflineStorageDatabaseE nabled, true);
}

WebView *WebView::createWindow(QWebPage::WebWindowType type)
{
WebView *view = new WebView;
return view;

}



If anyone can help me on this, that would be great.

Thanks.

ChrisW67
4th May 2014, 21:36
The cached credentials will probably be available to all views that share the same QNetworkAccessManager. You create a new instance for each view.

prajith
5th May 2014, 05:20
Can you explain a bit more? as I'm just confused about this, or if you can show me some examples, that would be great.

ChrisW67
5th May 2014, 05:30
Every time you create a new WebView your code creates a new NetworkAccessManager. Therefore every view, including the one your createwindow() code creates, has a distinct QNetworkAccessManager and distinct set of cached credentials and has to separately authenticate. You fix this by sharing the same NetworkAccessManager between WebViews.

prajith
5th May 2014, 07:22
Thanks for your help, I'm trying to implement new code right now.

Hope I can make it work :)

btw, do you have any examples?