PDA

View Full Version : Cookie problem with QtWebkit



vides2012
23rd June 2009, 21:15
Hi!

I would like to use QtWebkit to log in to a site, and then download some data.Unfortunately if I load the page with the webkit( QWebView::load()) I cant log in, and the site claims that I don't have cookies enabled, even though I have created a QNetworkCookieJar, and set it to the QNetworkAccessManager of the page.

here's a piece of my code:


Downloader::Downloader(QWidget *parent)
: QMainWindow(parent), ui(new Ui::DownloaderClass),state(First)
{
manager=new QNetworkAccessManager();
jar=new MyCookieJar();
manager->setCookieJar(jar);
view=new QWebView();
view->setMinimumSize(800,600);
connect(view,SIGNAL(loadFinished(bool)),this,SLOT( loaded(bool)));
view->load(QUrl("http://portfolio.hu/users/elofizetes_info.php?t=koteslista"));
QWebSettings::globalSettings()->setOfflineStoragePath("C:\\Users\\Zsolt\\Desktop\\");
}

the MyCookieJar is a subclass of QNetworkCookieJar class and only implements a getCookies() function, returning all the coookies stored ( the QNetworkCookieJar::allCookies() function is protected). In the loaded(bool) function i print all the cookies stored.
I only got a "cookie = 1;", and normally i would have a lot more( checked with wireshark).
And since i can only set the QNetworkAccessManager to a page, i do that every time the view loads one.

I tried to manually copy the protocol, and save the cookies, using QHttp, and the headers, but apparently some javascript code generates an ID to be sent to the site when logging in.

Please help me log in(and stay logged in) either with using QtWebkit, or with simple QHttp classes.

Any reply would be appreciated.

vides2012
25th June 2009, 22:24
Solved it.
I found the javascript code generating the cookie, copied it, and then I had to set some values in the cookie header(host,origin,referer,user-agent,...)

GeppyZ
25th March 2010, 16:44
Hi iam also working on saving cookies to disk. I see you have already solved your problem however, could you show me how your MyCookieJar class works?

Thanks in advance.

jay
8th April 2010, 14:42
Hi all,

I am loading a URL into the WebView (using load () method), this URL having UserLogin with Remember me option. Can any one help me how to remember UserLogin by enabling Cookie.

Regards,
Jay.