Login code



  • I am trying to write a program that logins on a website.Inspired by "this class":http://developer.qt.nokia.com/forums/viewthread/10771/ .I've added a few slots like:
    @void _q_on_loginphp();
    void _q_on_cookiephp();
    void _q_on_gamephp();@

    I am trying to simulte this requests:
    http://imageshack.us/photo/my-images/195/requestst.png/()
    In the login request I receive a sesion cookie :
    http://img20.imageshack.us/img20/3933/sidod.jpg
    On the last request I get an error.It says that it used the wrong sid
    Here is the code of my functions:
    @void Authenticator::_q_onLoginRequestFinished()
    {
    qDebug() << Q_FUNC_INFO;
    QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
    if ( !reply )
    return;
    QFile file("index.txt");
    QList<QByteArray> info=reply->rawHeaderList();
    file.open(QIODevice::WriteOnly);
    file.write("index \n");
    for(int i=0; i<info.size(); ++i){
    QString sourcecode(reply->rawHeader(info[i]));
    file.write(sourcecode.toLatin1());
    file.write("\n");
    }
    QNetworkRequest loginphp;
    QString url(reply->rawHeader(QByteArray("Location")));
    loginphp.setUrl( url);
    loginphp.setRawHeader( "User-Agent", " Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7" );

    QNetworkReply* loginphpReply = m_nam->get(loginphp);
    connect( loginphpReply, SIGNAL( finished() ),
    SLOT( _q_on_loginphp() ) );
    }
    void Authenticator::_q_on_loginphp()
    {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
    QFile file("loginphp");
    QList<QByteArray> info=reply->rawHeaderList();
    file.open(QIODevice::WriteOnly);
    file.write("loginphp \n");
    for(int i=0; i<info.size(); ++i){
    QString sourcecode(reply->rawHeader(info[i]));
    file.write(sourcecode.toLatin1());
    file.write("\n");
    }

    QNetworkRequest cookiephp;
    QString url(reply->rawHeader(QByteArray("Location")));
    cookiephp.setUrl(url);
    cookiephp.setRawHeader( "User-Agent", " Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7" );

    QNetworkReply* cookiephpReply = m_nam->get(cookiephp);
    connect( cookiephpReply, SIGNAL( finished() ),
    SLOT( _q_on_cookiephp() ) );
    }
    void Authenticator::_q_on_cookiephp()
    {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
    QFile file("cookiephp.txt");
    QList<QByteArray> info=reply->rawHeaderList();
    file.open(QIODevice::WriteOnly);
    file.write("cookiephp \n");
    for(int i=0; i<info.size(); ++i){
    QString sourcecode(reply->rawHeader(info[i]));
    file.write(sourcecode.toLatin1());
    file.write("\n");
    }
    QNetworkRequest gamephp;
    QString url("http://ro27.triburile.ro/game.php?screen=overview&intro");
    gamephp.setUrl(url);
    gamephp.setRawHeader( "User-Agent", " Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7" );
    QNetworkReply* gamephpReply = m_nam->get(gamephp);
    connect( gamephpReply, SIGNAL( finished() ),
    SLOT( _q_on_gamephp() ) );

    }
    void Authenticator::_q_on_gamephp()
    {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
    QFile file("gamephp.txt");
    QList<QByteArray> info=reply->rawHeaderList();
    file.open(QIODevice::WriteOnly);
    file.write("gamephp \n");
    for(int i=0; i<info.size(); ++i){
    QString sourcecode(reply->rawHeader(info[i]));
    file.write(sourcecode.toLatin1());
    file.write("\n");
    }

    }@
    The text output in gamephp.txt is :
    gamephp
    PHP/5.3.3-7+squeeze3
    http://www.triburile.ro/sid_wrong.php
    gzip
    Accept-Encoding
    text/html; charset=utf-8
    chunked
    Sun, 12 Feb 2012 15:58:32 GMT
    lighttpd/1.4.28

    [EDIT: fixed link, Volker]


Log in to reply
 

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