Results 1 to 10 of 10

Thread: sending cookies using qt

  1. #1
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default sending cookies using qt

    I am trying to send cookies using Qnetworkaccessmanager in visual studio2010.
    I have to send lso cookie with the http request. The cookie is already stored in my system.
    Help appreciated in advance!!

  2. #2
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: sending cookies using qt

    Quote Originally Posted by avipachar View Post
    The cookie is already stored in my system.
    Where it is saved?

    You should use QNetworkAccessManager::setCookieJar() to manage cookies.
    Oleg Shparber

  3. The following user says thank you to Oleg for this useful post:

    avipachar (22nd November 2011)

  4. #3
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: sending cookies using qt

    it is saved at C:\Users\AP\AppData\Roaming\Macromedia\Flash Player\#SharedObjects\98PHLCCM.

    It is a LSO cookie.
    In cookie Jar we have to give QURL from which we can store cookies in CookieJar.
    can we store the LSO cookie from above Location to cookieJar, if yes How?
    Please tell.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: sending cookies using qt

    Flash cookies are saved and sent by the Flash applications embedded on the page, not in the same way as HTTP cookies.

  6. The following user says thank you to ChrisW67 for this useful post:

    avipachar (23rd November 2011)

  7. #5
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: sending cookies using qt

    I also have Http cookies for the same site. can you tell me how to send them using cookie jar?

  8. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: sending cookies using qt

    Attach a QNetworkCookieJar to your QNetworkAccessManager: any cookies received are stored and returned automatically. There is a mechanism in QNetworkCookieJar for pre-loading cookies should you need to do this.

  9. #7
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: sending cookies using qt

    Exact scenario is like this.
    there is a site which require authentication. I want that after the user has logged into the site through browser, i want that my code should take that cookie from
    hard disk and send a get request to portal with that cookie so that authentication is not required.
    I have read a lot about QNetworkcookieJar class, as per i understand it doesn't save cookies to hard disk and also doesn't pick the cookies from hard disk. For that we should extend the class. If i am right how i can do that? thank you for your help.

  10. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: sending cookies using qt

    QNetworkCookieJar doesn't know anything about other browser application cookie caches, any more than IE knows about Chrome's cookies.

    If you want to persist the cookie jar then you do what the friendly manual says:
    QNetworkCookieJar does not implement permanent storage: it only keeps the cookies in memory. Once the QNetworkCookieJar object is deleted, all cookies it held will be discarded as well. If you want to save the cookies, you should derive from this class and implement the saving to disk to your own storage format.
    The class provides several methods to access the cookies in the jar to read or write to file.

    If you want the QNetworkCookieJar to be a proxy to some other browser's cookie cache then you should subclass and read (at least) the other browser's cookie cache. How you do that is entirely dependent on the other browser, and it may not work if the other browser's cookies (particularly transient session cookies) have not been written to somewhere you can access them.

    You could just have the user log in using a Qt web view or form and submit the login request via your QNetworkAccessManager to capture the cookies.

  11. The following user says thank you to ChrisW67 for this useful post:

    avipachar (8th December 2011)

  12. #9
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: sending cookies using qt

    can you give me an example of how to send cookies using QNetworkAccessManager::setCookieJar(). I think for that i have to derive my cookiejar class from QNetworkcookieJar class to access its protected functions. please give a simple example having simple request.

  13. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: sending cookies using qt

    Attach a QNetworkCookieJar to your QNetworkAccessManager, make requests, cookies are stored and returned to the relevant servers automatically. There's nothing else to it. If the first request you make from your Qt program is the login request then you will have the session cookie(s) in your cookie jar and they will be returned with any subsequent request using the same jar.

    If you persist in using another browser to do the login then you want to make a QNetworkCookieJar derived proxy for another browser's cookie cache. There is no simple example. You will need to use whatever external API you have to access the other browser's cookies to load a QNetworkCookieJar and/or reimplement QNetworkCookieJar::cookiesForUrl() and QNetworkCookieJar::setCookiesFromUrl(). Degree of complexity increases if the cookies you gather in your Qt program must go back into the other browser's jar.

Similar Threads

  1. Cookies....Again....
    By TJSonic in forum Qt Programming
    Replies: 7
    Last Post: 22nd November 2011, 09:00
  2. Replies: 0
    Last Post: 31st October 2011, 12:33
  3. Enable cookies in webkit
    By RzuF in forum Qt Programming
    Replies: 6
    Last Post: 10th October 2011, 07:37
  4. QNetworkAccessManager can't handle multiple cookies?
    By krippy2k in forum Qt Programming
    Replies: 5
    Last Post: 7th June 2009, 23:12
  5. I get only 1 of 4 cookies...
    By cherva in forum Qt Programming
    Replies: 33
    Last Post: 5th June 2009, 15:42

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.