Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using CookieJar with QwebKit after cookie has bean writing how does the webkit recognize it ?

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

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved