PDA

View Full Version : Enable cookies in webkit



RzuF
7th October 2011, 14:01
Hi,

I need enable cookies in my app, because one site don't show until I enable cookies.
Of course i read other threads, but all people wrote that look in arora. Ok good, but arora is very big project and I can't find this code without knowleadge about all. Can someone who reolved this problem help me where do i have to look for?

I hope sb help me :D

wysota
7th October 2011, 19:35
QNetworkCookieJar
QNetworkAccessManager::setCookieJar()

RzuF
8th October 2011, 10:34
I read about this too, but i doesn't work.

I create QNetworkCookieJar and change it in my QNetworkAccessManager in QWebView. Web Page still give me an error about cookies ;[

wysota
8th October 2011, 14:56
So maybe the problem is not with cookies after all? Does your cookie jar accept cookies for the page?

RzuF
8th October 2011, 21:14
When i tried to read cookies from my jar nothing happens. Maybe cookiejar not accept cookies from this page but why? Can u tell me how to check this? And solve it? Anyway I try it.

EDIT:

When i created my own class to cookiejar and write simple function setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url) which display qmessagebox and return true, and it works, partly. Now i have error about bad send request.

Whatever thx for help. I'll work how to solve it :) I think when i save cookie i will be fine. Whan i do it i will post my results here :D

RzuF
9th October 2011, 19:11
I back to point 0. I wrote 2 functions. setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url) and cookiesForUrl(const QUrl &url) const

Page returns me an error that i haven't got enabled cookies. Before add functions' body page returns me an error about bad send request. I thought it is good, because all functions works. First page wants cookie, than send me cookie (first time, there isn't cookie with this url) read cookies and send me more cookies (now there is a url and only change cookies for that url).

Here is my code. Maybe I do something wrong? Or I do it bad way. I don't know and ask for help.


bool QNCJ::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url)
{
QWidget lol;

bool done = false;
bool exist = false;
int exist_id;

for(int i=0; i<cookiez.size(); i++)
{
if(cookiez.at(i).url==url)
{
exist = true;
exist_id = i;
}
}

if(exist)
{
//cookiez.at(exist_id).setCookie(cookieList);
cookiez[exist_id].setCookie(cookieList);
done = true;

QMessageBox::information(&lol, "Istnieje", "YAP");
}

else
{
CookieContainer temp(cookieList, url);
cookiez << temp;
done = true;
QMessageBox::information(&lol, "Nie Istnieje", "Nope");
}




return done;
}


QList<QNetworkCookie> QNCJ::cookiesForUrl(const QUrl &url) const
{
bool exist;
int exist_id;

for(int i=0; i<cookiez.size(); i++)
{
if(cookiez.at(i).url==url)
{
exist = true;
exist_id = i;
}
}

QList<QNetworkCookie> cookies;

QWidget lol;

if(exist)
{
cookies = cookiez.at(exist_id).cookies;
QMessageBox::information(&lol, "Dawaj!", "Dawaj cooksy!");
}




return cookies;
}



class CookieContainer
{

public:
explicit CookieContainer(QObject *parent = 0);
CookieContainer(QList<QNetworkCookie> cookieList, QUrl urlz);

QUrl url;
QList<QNetworkCookie> cookies;

void setCookie(QList<QNetworkCookie> cookieList);

};

I add variable cookiez is QList<CookieContainer>

wysota
10th October 2011, 07:37
You don't have to subclass QCookieJar. The default implementation already provides everything that is needed.