QWebView cookies?
Hi,
I want to show some web page on QWebView. But this page require authentication.
Authentication token ( and some other properties ) should be passed via standard http cookie.
How can i do that? Any suggestion, code examples?
I tried follwing:
- cookies.append(cookie);
- MyCookieJar*cookieJar = new MyCookieJar(this);
- cookieJar->setCookies(cookies);
- _webView->page()->networkAccessManager()->setCookieJar(cookieJar);
- _webView->load( url );
Note:
MyCookieJar just extedn QNetworkCookieJar and override protected function void setAllCookies ( const QList<QNetworkCookie> & cookieList )
Any idea?
Many Thanks for any help!
[EDIT: fixed code syntax typo, Volker]
4 replies
I think u can handle the event loadStarted of QWebView widget, then use webView->page()->mainFrame()->evaluateJavaScript to execute javascript to set cookies as u want. Good luck!
This is not an answer
I had the same problem you describe.You have to construct the cookie and not consider all the lines as one line…
You have to do like this :
- // I store the cokkies in base all the lines separated ny \n
- {
- cookie.setName(C.Name(elem));
- cookie.setValue(C.Value(elem));
- cookie.setDomain(C.Domain(elem));
- cookie.setExpirationDate(C.Expirationdate(elem));
- cookie.setPath(C.Path(elem));
- cookie.setHttpOnly(C.HttpOnly(elem));
- cookies.append(cookie);
- }
- MonCookieJar *jar = new MonCookieJar;
- jar->SetAllCookies(cookies);
C.name is a function reading a cookie line and extracting the value
- {
- }
You have to write Domain Value
For the ExpiratioDate you have to make a QDateTime fonction
be care QDateTime::fromString will work in your locale for me in france Lundi, dimanche etc.. you need to convert
- {
- date.replace(" GMT","");
- return (Date);
- }
[EDIT: fixed quote formatting and code formatting, please use @-tags for code and the quote linke for quoting comments, Volker]
You must log in to post a reply. Not a member yet? Register here!
