Page 1 of 2 12 LastLast
Results 1 to 20 of 34

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

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

    Default I get only 1 of 4 cookies...

    I'm trying to get a web page that returns to me 4 cookies with this part of code:
    Qt Code:
    1. QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    2. QNetworkRequest request;
    3. request.setUrl(QUrl(line));
    4. request.setRawHeader("User-Agent", "Firefox/3.0.10");
    5.  
    6. reply = manager->get(request);
    7.  
    8. connect(reply, SIGNAL(finished()), this, SLOT(slotReadyRead()));
    9.  
    10. void Window::slotReadyRead(){
    11. QList<QByteArray> headers=reply->rawHeaderList();
    12. QVariant cookies=reply->header(QNetworkRequest::SetCookieHeader);
    13. wget = reply->readAll();
    14. QList<QVariant> list = cookies.toList();
    15. qDebug()<<"HEADERS: "<< headers[2] << " COOKIES: " << list.size();
    16. qDebug()<<"COOKIES FROM rawHEADER: " << reply->rawHeader("Set-Cookie") ;
    17. ...
    18. ...
    19. ...
    To copy to clipboard, switch view to plain text mode 
    The output of the program is:
    Qt Code:
    1. HEADERS: "Set-Cookie" COOKIES: 0
    2. COOKIES FROM rawHEADER: "JSESSIONID=F9C30312025976F6A8A4813CC96B8E65; Path=/app"
    To copy to clipboard, switch view to plain text mode 
    The cookies from rawHEADER is only 1 ... the server sends 4... what is wrong ?

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    How does the raw header list look if you iterate over it and print it, e.g.

    Qt Code:
    1. foreach( QByteArray b, reply->rawHeaderList() )
    2. qDebug() << b;
    To copy to clipboard, switch view to plain text mode 

    Perhaps there are several set cookie entries....

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

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

    OUTPUT:
    Qt Code:
    1. B: "Date"
    2. B: "Server"
    3. B: "Set-Cookie"
    4. B: "Vary"
    5. B: "Content-Encoding"
    6. B: "Pragma"
    7. B: "Cache-Control"
    8. B: "Connection"
    9. B: "Content-Type"
    10. HEADERS: "Set-Cookie" COOKIES: 0
    11. COOKIES FROM rawHEADER: "JSESSIONID=669579C9DD7AE23FFA6EEA7FF9E30E7C; Path=/app"
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    Have you used wireshark or something similar to verify that you actually do get four cookies?

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

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

    Yes, Wireshark sends me 4 cookies:
    Qt Code:
    1. Transmission Control Protocol, Src Port: http (80), Dst Port: 41003 (41003), Seq: 1, Ack: 178, Len: 580
    2. Hypertext Transfer Protocol
    3. HTTP/1.1 302 Moved Temporarily\r\n
    4. Date: Mon, 04 May 2009 13:09:58 GMT\r\n
    5. Server: Apache\r\n
    6. Set-Cookie: JSESSIONID=4D6B05D58928843F51D03F6D85ED5F40; Path=/app\r\n
    7. SET-COOKIE: _key=7710db16cea77c8152a557a0ab0469cc; Path=/app; HTTPOnly\r\n
    8. Set-Cookie: uhost=mail33.abv.bg; Domain=.abv.bg; Path=/\r\n
    9. Set-Cookie: usid=4D6B05D58928843F51D03F6D85ED5F40; Domain=.abv.bg; Path=/\r\n
    10. Location: http://mail33.abv.bg/app/j/home.jsp\r\n
    11. Content-Length: 0\r\n
    12. Pragma: no-cache\r\n
    13. Cache-Control: no-cache\r\n
    14. Vary: User-Agent\r\n
    15. Keep-Alive: timeout=5, max=100\r\n
    16. Connection: Keep-Alive\r\n
    17. Content-Type: text/xml;charset=utf-8\r\n
    To copy to clipboard, switch view to plain text mode 
    The strange thing is that the output of the program was:
    Qt Code:
    1. COOKIES FROM rawHEADER: "JSESSIONID=D106ADD7E19F1913E020E542B8C73EFB; Path=/app"
    To copy to clipboard, switch view to plain text mode 
    the cookie is not the same

  6. #6
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    Comparing your wireshark output to the output from the foreach-loop described earlier, you seem to miss other entries as well.

    What do you get from reply.readAll() ?

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

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

    I get the page that I should get when I login with wrong user or password or in my case with wrong cookies....

  8. #8
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    Does that mean that you have to add something to your request? Or do you mean that you get too few cookies but expect it to work?

  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 need all four cookies it won't work with just one.

  10. #10
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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


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

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

    Can you tell me how to check because allCookies() is protected and I don't want to subclass the whole class....

  12. #12
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    I'd go or the cookiesForUrl function.

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

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

    I inserted
    Qt Code:
    1. QList<QNetworkCookie> jar=manager->cookieJar()->cookiesForUrl(QUrl(line));
    To copy to clipboard, switch view to plain text mode 
    on line 7
    and in debug mode jar stayed empty until the program ended.

  14. #14
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    How does the original URL look? Do you try to login here, or do you try to access some location where you already are logged in? If so, how did you originally log in there?

    You say that you reach the login/wrong password page, and that seems reasonable to me if you don't have any cookies...

  15. #15
    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.

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.


  17. #17
    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.

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.


  19. #19
    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

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.


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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.