Why my custom cookiejar not working?



  • I need to load cookie from local disk via qnetworkcookiejar, but it doesnot work when I try it. Here is my code:
    @QApplication a(argc, argv);

    QNetworkCookieJar *cookieJar = new QNetworkCookieJar;
    QFile file("d:/cookie.txt");
    file.open(QIODevice::ReadOnly | QIODevice::Text);
    QTextStream in(&file);
    while (!in.atEnd()) {
    QString line = in.readLine();
    QList<QNetworkCookie> cookie = QNetworkCookie::parseCookies(line.toLocal8Bit());
    foreach (QNetworkCookie c, cookie) {
    qDebug() << cookieJar->insertCookie(c);
    }
    }
    QUrl url = QUrl(QString("http://www.renren.com/"));

    QWebView view;
    QWebInspector inspector;
    inspector.setPage(view.page());
    view.settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
    view.settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, false);

    QNetworkAccessManager *manager = new QNetworkAccessManager;
    manager->setCookieJar(cookieJar);
    view.page()->setNetworkAccessManager(manager);

    inspector.setVisible(true);
    view.show();
    QEventLoop loop;
    QObject::connect(&view, SIGNAL(loadFinished(bool)),
    &loop, SLOT(quit()));
    view.load(QString("http://www.renren.com"));
    return a.exec();
    @

    the content of d:/cookie.txt:

    @anonymid=hqazrdfcujqlcw; expires=Thu, 10-Jan-2019 14:50:55 GMT; domain=.renren.com; path=/
    depovince=ZGQT; expires=Tue, 14-Jan-2014 14:50:55 GMT; domain=.renren.com; path=/
    jebecookies=1e67b394-5310-4ba3-899c-4bfe76a48eaf|||||; domain=.renren.com; path=/
    r01=1; expires=Tue, 06-Jan-2015 14:50:55 GMT; domain=.renren.com; path=/
    JSESSIONID=abc-myf8pCJA6hWBmYbou; domain=www.renren.com; path=/
    ick_login=f8c346c3-cfb3-48d6-9420-1762fab34171; domain=.renren.com; path=/
    UID=649f302-216.156.147.49-1389451858; expires=Fri, 01-Jan-2016 14:50:58 GMT; domain=.scorecardresearch.com; path=/
    UIDR=1389451858; expires=Fri, 01-Jan-2016 14:50:58 GMT; domain=.scorecardresearch.com; path=/
    _de=040F82A18DD5747B2955652844C08B9F34DF20B0B3AA6FF7; expires=Tue, 06-Jan-2015 14:51:37 GMT; domain=.renren.com; path=/
    p=1926b0e5257c8146601b4d063586f4c94; expires=Mon, 10-Feb-2014 14:51:37 GMT; domain=.renren.com; path=/
    ap=175034604; expires=Mon, 10-Feb-2014 14:51:37 GMT; domain=.renren.com; path=/
    first_login_flag=1; domain=.renren.com; path=/
    t=61569f309ee6301116241f66ab6d018e4; domain=.renren.com; path=/
    t=b83a0150ef41ddebd7f3937b11886a70; domain=.renren.com; path=/xtalk/
    societyguester=61569f309ee6301116241f66ab6d018e4; domain=.renren.com; path=/
    id=175034604; domain=.renren.com; path=/
    xnsid=7e369346; domain=.renren.com; path=/
    loginfrom=syshome; domain=.renren.com; path=/
    loginfrom=null; domain=.renren.com; path=/
    feedType=175034604_hot; expires=Mon, 10-Feb-2014 14:51:38 GMT; domain=.www.renren.com; path=/
    an_slot=115; domain=ebp.renren.com; path=/ebpn
    today=22.51; expires=Sat, 11-Jan-2014 15:59:59 GMT; domain=wpi.renren.com; path=/wtalk/
    @

    it seems no Cookie in webinspector when I load www.renren.com. Can some one help me?


Log in to reply
 

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