QNetworkAccessManager: How to enable cookies / How to Facebook login?



  • Sometimes when you want to log in to a website you are told that yo have to enable cookies in your browser.
    I would like to know how to "enable" those cookies when doing the website login with QNetworkAccessManager:post().
    Any ideas?

    EDIT: To be more precise, I want to do a Facebook login by sending the parameters "email" and "pass" to Facebook's login.php, but always get told that I have to enable cookies in my browser's security settings.
    Am I right in thinking that by opening the startpage facebook.com some cookies are transmitted in the http header that later have to be sent back when calling the login form?

    EDIT2: So my actual question is, how does facebook login decide whether a user has cookies turned on or not. What actually makes my problem less Qt-Programming related, but maybe anyone still knows a solution.



  • Facebook knows you are not returning its cookies simply because you do not return them.

    QNetworkAccessManager uses a QNetworkCookieJar to store cookies. If cookies are in the jar for the site they will be sent automatically, you do not need to do anything special. The default cookie jar implementation has no persistent storage so cookies are only good for the lifetime of the QNetworkAccessManager and QNetworkCookieJar. If you create a new QNetworkAccessManager for each request then you will never have cookies to return.

    See QNetworkAccessManager::setCookieJar() and subclass QNetworkCookieJar if you want to implement some form of cookie persistence.



  • Thank you. It is as you said.
    I just had to use the same nam for opening the startpage and the login page after having assigned a CookieJar before. Works fine now.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.