Results 1 to 20 of 34

Thread: I get only 1 of 4 cookies...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I get only 1 of 4 cookies...

    Here is the deal:
    1) I send the user and password to the server that the original http://abv.bg 's form will send the data.
    2) The server returnes me "HTTP 302 Moved temporarily" and a link like:
    http://mailXX.abv.bg/servlet/plogin?s=hewirhwekrjhwekjrhw.passportX" wher re X's are random nubers.
    3) When I go to that page I get the same HTTP 302 Moved temprarily message but with differtent mailXX.
    4) I go there and this page gives me 4 cookies: example:
    Qt Code:
    1. Set-Cookie: JSESSIONID=4D6B05D58928843F51D03F6D85ED5F40; Path=/app\r\n
    2. SET-COOKIE: _key=7710db16cea77c8152a557a0ab0469cc; Path=/app; HTTPOnly\r\n
    3. Set-Cookie: uhost=mail33.abv.bg; Domain=.abv.bg; Path=/\r\n
    4. Set-Cookie: usid=4D6B05D58928843F51D03F6D85ED5F40; Domain=.abv.bg; Path=/\r\n
    To copy to clipboard, switch view to plain text mode 
    and redirects me to "http://mailXX.abv.bg/app/j/home.jsp" whre the XX are from the last page . ( the page that gave me the cookies)
    This is what I need. I used WGET to deal with the cookies and everything is ok, but my program reached version 1.00 and I want to remove it because it's stupid for the windows version to come with a hidden wget.exe in the same folder.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: I get only 1 of 4 cookies...

    In general I'd say that what the server returns you could be a bit invalid. From what I understand (I could be wrong though) there should only be one header of each type therefore you only get one set-cookie header that contains all cookies that are to be set separated by semicolons.

    QNetworkReply::header() should return you a QVariant when passed QNetworkRequest::SetCookieHeader. This variant is really QList<QNetworkCookie>. When you get hold of it, you can list its contents to check out what cookies you are set. Then you can store them in your cookie-jar.

    Be sure to cast the variant to a proper type or else you will get an empty list like you do now.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I get only 1 of 4 cookies...

    I tried that on line 12 and 14 on the first post and "list" is empty.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: I get only 1 of 4 cookies...

    Quote Originally Posted by cherva View Post
    I tried that on line 12 and 14 on the first post and "list" is empty.
    Read again my last sentence and see what QVariant::toList() returns.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2009
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I get only 1 of 4 cookies...

    Qt Code:
    1. QVariant cookies=reply->header(QNetworkRequest::SetCookieHeader);
    2. QList<QVariant> list = cookies.toList();
    To copy to clipboard, switch view to plain text mode 
    Makes cookies = QList<QNetworkCookie> and list = 0 items

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: I get only 1 of 4 cookies...

    No, it makes it QList<QVariant> and not QList<QNetworkCookie> thus the size is 0 (because it is not a QList<QVariant>).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2009
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I get only 1 of 4 cookies...

    Aaaammm "No, it makes it QList<QVariant>............ (because it is not a QList<QVariant>)." ?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: I get only 1 of 4 cookies...

    Quote Originally Posted by cherva View Post
    Aaaammm "No, it makes it QList<QVariant>............ (because it is not a QList<QVariant>)." ?
    I suggest you rephrase this post because I have no idea what you mean. If it's that you don't see a difference between QVariant and QNetworkCookie then I suggest you click both links and read the docs to see the differences. You are trying to convert a QVariant holding a QList<QNetworkCookie> into QList<QVariant> which it is not thus you get an empty QList<QVariant>. It's like you wanted to convert a rectangle into a circle - you'd get an invalid circle because rectangles can't be converted to circles without actually knowing what a "rectangles" and "circles" are.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    May 2009
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I get only 1 of 4 cookies...

    I didn't understand what he posted.... at firs he says that it's a QList<QVariant> and then in the brackets he says that it's not QList<QVariant>, but never mind that. I don't know how to convert it to a QList<QNetworkCookie> ? I guess not like
    Qt Code:
    1. QList<QNetworkCookie> list = cookies.toList();
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: I get only 1 of 4 cookies...

    Quote Originally Posted by cherva View Post
    at firs he says that it's a QList<QVariant>
    No, at first "he" says the cast tries to make it QList<QVariant>.

    and then in the brackets he says that it's not QList<QVariant>,
    Yes, so "he" says.

    but never mind that.
    Actually you should mind because it is the most important part of the whole discussion.

    I don't know how to convert it to a QList<QNetworkCookie> ? I guess not like
    Qt Code:
    1. QList<QNetworkCookie> list = cookies.toList();
    To copy to clipboard, switch view to plain text mode 
    I guess the compiler already told you it is not the right route...

    Try this:
    Qt Code:
    1. QList<QNetworkCookie> cookieList = qvariant_cast<QList<QNetworkCookie> >(cookies);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    May 2009
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I get only 1 of 4 cookies...

    I don't know how to explain what happened...
    My cookieList has 1 item: "d" wich is a QSharedDataPointer<QNetworkCookiePrivate> wich has another "d" wich is QNetworkCookiePrivate * with value 0x1 there is *d inside it wich is QNetworkCookiePrivate and insite that there is a QSharedData (commend,domain,expirationDate,httpOnly,name,path, secure,value) and they are all "not in scope"

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: I get only 1 of 4 cookies...

    Quote Originally Posted by cherva View Post
    I don't know how to explain what happened...
    You tried debugging a class your debugger has no support for. That's normal. Forget the debugger - after making the cast see the size of the list. If it is 0 then it's not a list but rather a QNetworkCookie object which would be strange. Try running this code (assuming "rep" is your QNetworkReply object):

    Qt Code:
    1. QVariant var = rep->header(QNetworkRequest::SetCookieHeader);
    2. qDebug() << "Cookies set:" << var;
    3. QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie> >(var);
    4. foreach(QNetworkCookie c, cookies){
    5. qDebug() << QString(c.toRawForm());
    6. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.