PDA

View Full Version : sending cookies using qt



avipachar
21st November 2011, 09:13
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!!

Oleg
21st November 2011, 11:45
The cookie is already stored in my system.
Where it is saved?

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

avipachar
22nd November 2011, 04:10
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.

ChrisW67
22nd November 2011, 06:14
Flash cookies are saved and sent by the Flash applications embedded on the page, not in the same way as HTTP cookies.

avipachar
22nd November 2011, 09:03
I also have Http cookies for the same site. can you tell me how to send them using cookie jar?

ChrisW67
23rd November 2011, 04:38
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.

avipachar
23rd November 2011, 04:45
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.

ChrisW67
23rd November 2011, 05:04
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.

avipachar
8th December 2011, 10:49
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.

ChrisW67
8th December 2011, 23:30
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.