Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Extracting information from a password protected web page.
Forum Updated to NodeBB v4.3 + New Features

[solved] Extracting information from a password protected web page.

Scheduled Pinned Locked Moved General and Desktop
15 Posts 4 Posters 7.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr.FreakyJo
    wrote on last edited by
    #6

    Helped me too,but I don't undestand them to well.I'm new to Qt(read only one manual about Qt 4) and I don't know too much of the new versions.If you could explain me how this work it would be a huge help.A manual,tutorial,book would also help.I'm trying to login on http://www.triburile.ro/

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #7

      It's all there in the above code sample. It just creates a QNetworkRequest for the url to which you wish to send the request. The request is then sent to the server via the QNetworkAccessManager::post() function along with a QByteArray containing the filled in form data in a percent-encoded format.

      We then connect up to various signals to process the reponses we may get back.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mr.FreakyJo
        wrote on last edited by
        #8

        I kind of understood this but that encoding works on all websites?I modified that code with the link of my website ,username and password.In params.addEncodedQueryItem( "username", ai modified username to user as it is in the source code of the page.In the debuger i get the error "Loging request failed: Moved Permanently." .Thank you for your help.

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #9

          It depends on what they use for the form. The above example uses the HTTP post method. What does your form look like? What URL is it, the error you are seeing looks like you have the wrong URL in your request?

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mr.FreakyJo
            wrote on last edited by
            #10

            I'm trying to login on http://tribalwars.net . The source cod for those forms look like this :
            <input id="user" name="user" class="text" type="text" value=""
            onkeydown="if((e=window.event||event) && e.keyCode == 13) $('#login_form').trigger('submit');"/>
            </span>
            </label>
            <label for="password">
            <strong >Password:</strong>
            <span >
            <input name="clear" type="hidden" value="true" />
            <input id="password" name="password" class="text" type="password"
            onkeydown="if((e=window.event||event) && e.keyCode == 13) $('#login_form').trigger('submit');"/>
            </span>
            </label>

            <div id="js_login_button">
            <a href="#" class="login_button">
            <span class="button_left"></span>
            <span class="button_middle">Login</span>
            <span class="button_right"></span>
            </a>
            </div>

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZapB
              wrote on last edited by
              #11

              And can you show your C++ code you are trying to use please?

              Nokia Certified Qt Specialist
              Interested in hearing about Qt related work

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mr.FreakyJo
                wrote on last edited by
                #12

                It's your code with some modifications to the login function:

                @void Authenticator::login( const QString& userName, const QString& password )
                {
                qDebug() << "Attempting to login with Username =" << userName << "and password =" << password;
                m_userName = userName;

                QNetworkRequest request;
                request.setUrl( QUrl( "http://tribalwars.net/" ) );
                request.setRawHeader( "User-Agent", " Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7" );
                request.setHeader( QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded" );
                
                // Construct a suitable byte array for the form fields and values
                QUrl params;
                params.addEncodedQueryItem( "ACT", QUrl::toPercentEncoding( "11" ) );
                params.addEncodedQueryItem( "RET", QUrl::toPercentEncoding( "/" ) );
                params.addEncodedQueryItem( "site_id", QUrl::toPercentEncoding( "1" ) );
                params.addEncodedQueryItem( "user", QUrl::toPercentEncoding( userName ) );
                params.addEncodedQueryItem( "password", QUrl::toPercentEncoding( password ) );
                //params.addEncodedQueryItem( "openid", QUrl::toPercentEncoding( "" ) );
                //params.addEncodedQueryItem( "auto_login", QUrl::toPercentEncoding( "1" ) );
                
                // The encoded string contains a ? at the beginning, strip it off
                QByteArray paramBytes = params.toString().mid( 1 ).toLatin1();
                
                /** \bug For some reason QUrl::toPercentEncoding() does not encode "/" as "/" */
                paramBytes.replace( "/", "/" );
                //qDebug() << "Form data =" << paramBytes;
                
                QNetworkReply* reply = m_nam->post( request, paramBytes );
                connect( reply, SIGNAL( finished() ),
                         SLOT( _q_onLoginRequestFinished() ) );
                connect( reply, SIGNAL( metaDataChanged() ),
                         SLOT( _q_onLoginMetaDataChanged() ) );
                connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
                         SLOT( _q_onLoginRequestError( QNetworkReply::NetworkError ) ) );
                

                }@

                And in main where I test it i called the function like this
                tribalwars->login(QString("mr.freakyjo"),QString("password"));
                tribalwars being an "Authenticator *" object.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Mr.FreakyJo
                  wrote on last edited by
                  #13

                  I think i can log in with a MD5 hash of a string consisting of the variables “sid”, “username” and “secret” together. e.g. $hash = md5($sid . $username . $secret_password); .How can I do this in QT?Thank you for your help.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mr.FreakyJo
                    wrote on last edited by
                    #14

                    Modified the code and now I can login.A link to a more detailed manual for the webkit and QtNetwork or for a book would be a huge help now.Thank you ZapB for helping me!

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Mr.FreakyJo
                      wrote on last edited by
                      #15

                      After monitoring http request with the help off google chrome I see that a http post request is made by a script.I see that it’s initiator is game.js:17 (a javascript).Can I make a http request to that script or how can I do it?Is it necessary to use XMLHttpRequest?The scripts takes a user and a password and returns a form and there is some information in that form that I need to login.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved