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

    For anyone having the same issue this problem is fixed in QT 4.5.2 and UP.
    Thanks ChrisW67, and wysota.

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.