Using CookieJar with QwebKit after cookie has bean writing how does the webkit recognize it ?



  • Hello all
    i added CookieJar to my qwebkit browser component , the cookie is written like it suppose to to file , and when the browser loaded
    i "Think" it reading the Cookie , but still the site acts like it dosn't find the cookie .
    what can it be ?
    here is my cooikeJar code ( it saves and read the cookie just fine )

    @#include "cookiejar.h"
    #include <QDir>
    #include <QFile>
    #include <QDateTime>
    #include <QDebug>
    #include "Constants.h"
    CookieJar* CookieJar::jar = 0;

    CookieJar::CookieJar(QObject *parent) : QNetworkCookieJar(parent) {

    //Read saved cookies
    QFile cookies(QDir::homePath()+"/"+COOCKIE_DIR+"/cookies");
    if (cookies.exists()) {
    QList<QNetworkCookie> cookieList;
    cookies.open(QFile::ReadOnly);
    while (cookies.bytesAvailable()) {
    QByteArray arr = cookies.readLine();
    QString cookie = QString::fromUtf8(arr);
    if (cookie.endsWith("\n")) cookie.chop(1);
    cookieList.append(QNetworkCookie::parseCookies(cookie.toUtf8()));
    }
    cookies.close();
    setAllCookies(cookieList);
    }

    saveAll = true;
    }

    void CookieJar::saveCookies() {
    QFile cookieFile(QDir::homePath()+"/"+COOCKIE_DIR+"/cookies");
    cookieFile.open(QFile::WriteOnly);

    qDebug() << "Saving all cookies: " << saveAll;
    //Save cookies, if there are in the allowesCookieDomains-list
    QList<QNetworkCookie> cookies = allCookies();

    for (int i = 0; i < cookies.size(); i++) {
    bool allowed = false;

    //Check if cookies may not be saved
    if (cookies.value(i).isSessionCookie()) continue;
    if (cookies.value(i).expirationDate() < QDateTime::currentDateTime()) continue;

    //Only save non session cookies and is not expirated
    foreach (QString d, allowedCookieDomains) {
    if (saveAll || cookies.value(i).domain().endsWith(d)) {
    allowed = true;
    break;
    }
    }

    if (allowed) {
    cookieFile.write(cookies.value(i).toRawForm()+"\n");
    qDebug() << "Saved cookie from: " << cookies.value(i).domain();
    } else {
    qDebug() << "Discarded cookie from: " << cookies.value(i).domain();
    }
    }
    cookieFile.flush();
    cookieFile.close();

    }

    void CookieJar::saveWhiteList() {
    QFile allowedDomains(QDir::homePath()+"/"+COOCKIE_DIR+"/whitelistCookies");
    allowedDomains.open(QFile::WriteOnly);
    foreach(QString domain, allowedCookieDomains) {
    allowedDomains.write((domain.toUtf8()+"\n"));
    }
    allowedDomains.flush();
    allowedDomains.close();

    qDebug() << "Cookie whitelist saved.";
    }
    @

    the allowedCookieDomains is filled with the right dommains


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.