[solved] Extracting information from a password protected web page.
-
Thank you! These suggestion provides me a good starting point. I'll look in to the information you suggested!
Br
Richard -
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/
-
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.
-
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.
-
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?
-
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> -
And can you show your C++ code you are trying to use please?
-
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. -
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.
-
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!
-
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.