Perhaps would you want to get a look to my code :
"IL" (Intranet_Login) concerns the initial POST() request, that connect the client to the "courriel" page (authentification).
"RC" (Recuperer_Comptes) concerns the GET() request, that download a page once we are connected.
The initial request (post) get the cookie value and store it in "cookie".
The second request (get) set this cookie value in his header.
#include <QApplication>
#include <QByteArray>
#include <iostream>
#include "HTTPChecker.h"
int main(int argc, char *argv[])
{
identifiant = "Stagiaire";
password = "/QDMSy9P";
HTTPChecker *httpChecker = new HTTPChecker();
httpChecker->Intranet_Login(identifiant, password);
return app.exec();
}
#include <QApplication>
#include <QByteArray>
#include <iostream>
#include "HTTPChecker.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
identifiant = "Stagiaire";
password = "/QDMSy9P";
HTTPChecker *httpChecker = new HTTPChecker();
httpChecker->Intranet_Login(identifiant, password);
return app.exec();
}
To copy to clipboard, switch view to plain text mode
HTTPChecker
::HTTPChecker() : QObject(){
cookie = ""; // Holds the cookie value, from the POST() request
IL_NB_erreurs = 0;
IL_http
= new QHttp("courriel",
80);
connect(IL_http, SIGNAL(done(bool)), this, SLOT(SLOT_IL_showPage()));
connect(IL_http, SIGNAL(requestFinished(int, bool)), this, SLOT(SLOT_IL_httpRequestFinished(int, bool)));
RC_NB_erreurs = 0;
RC_http
= new QHttp("courriel",
80);
connect(RC_http, SIGNAL(done(bool)), this, SLOT(SLOT_RC_showPage()));
connect(RC_http, SIGNAL(requestFinished(int, bool)), this, SLOT(SLOT_RC_httpRequestFinished(int, bool)));
}
HTTPChecker::HTTPChecker() : QObject()
{
cookie = ""; // Holds the cookie value, from the POST() request
IL_NB_erreurs = 0;
IL_http = new QHttp("courriel", 80);
connect(IL_http, SIGNAL(done(bool)), this, SLOT(SLOT_IL_showPage()));
connect(IL_http, SIGNAL(requestFinished(int, bool)), this, SLOT(SLOT_IL_httpRequestFinished(int, bool)));
connect(IL_http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),this, SLOT(SLOT_IL_readResponseHeader(const QHttpResponseHeader &)));
RC_NB_erreurs = 0;
RC_http = new QHttp("courriel", 80);
connect(RC_http, SIGNAL(done(bool)), this, SLOT(SLOT_RC_showPage()));
connect(RC_http, SIGNAL(requestFinished(int, bool)), this, SLOT(SLOT_RC_httpRequestFinished(int, bool)));
connect(RC_http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),this, SLOT(SLOT_RC_readResponseHeader(const QHttpResponseHeader &)));
}
To copy to clipboard, switch view to plain text mode
First request : authentification :
{
// content //tg=login&login=login&referer=&nickname=stagiaire&password=%2FQDMSy9P&submit=Connexion
content.append("tr");
content.append("=");
content.append("login");
content.append("login");
content.append("=");
content.append("login");
content.append("referer");
content.append("=");
content.append("");
content.append("nickname");
content.append("=");
content.append(identifiant);
content.append("&");
content.append("password");
content.append("=");
content.append(password);
content.append("&");
content.append("submit");
content.append("=");
content.append("Connexion");
// header
header.setValue("Host", "courriel");
header.setContentType("application/x-www-form-urlencoded");
header.setContentLength(content.length());
// request
IL_httpId = IL_http->request(header, content);
}
void HTTPChecker::SLOT_IL_showPage()
{
if (IL_NB_erreurs == 0)
{
reponse_lisible.append(reponse);
reponse_lisible = reponse_lisible.section("** ",1,1);
reponse_lisible = reponse_lisible.section(" **",0,0);
std::cout << "-=" << reponse_lisible.toStdString() << "=-" << std::endl;
}
else
{
std::cout << "\n\nREPONSE : =-ERREURS-=\n---------" << std::endl;
}
Recuperer_Comptes(); // Call the second request
}
void HTTPChecker::SLOT_IL_httpRequestFinished(int requestId, bool error)
{
if (requestId != IL_httpId)
return;
if (error)
{
IL_NB_erreurs = IL_NB_erreurs + 1;
std::cout << "\n\nERREUR (IL_httpRequestFinished) : " << (IL_http->errorString()).toStdString() << std::endl;
}
}
{
if (responseHeader.statusCode() != 200)
{
IL_NB_erreurs = IL_NB_erreurs + 1;
std::cout << "\n\nERREUR (IL_readResponseHeader) : " << (responseHeader.reasonPhrase()).toStdString() << std::endl;
return;
}
QString cookie_value
= responseHeader.
value("set-cookie");
cookie_value = cookie_value.section(";", 0, 0);
cookie = cookie_value; // Store teh cokie value, for the second request
}
void HTTPChecker::Intranet_Login(QByteArray identifiant, QByteArray password)
{
// content //tg=login&login=login&referer=&nickname=stagiaire&password=%2FQDMSy9P&submit=Connexion
QByteArray content = "";
content.append("tr");
content.append("=");
content.append("login");
content.append("login");
content.append("=");
content.append("login");
content.append("referer");
content.append("=");
content.append("");
content.append("nickname");
content.append("=");
content.append(identifiant);
content.append("&");
content.append("password");
content.append("=");
content.append(password);
content.append("&");
content.append("submit");
content.append("=");
content.append("Connexion");
// header
QHttpRequestHeader header("POST", "/index.php");
header.setValue("Host", "courriel");
header.setContentType("application/x-www-form-urlencoded");
header.setContentLength(content.length());
// request
IL_httpId = IL_http->request(header, content);
}
void HTTPChecker::SLOT_IL_showPage()
{
if (IL_NB_erreurs == 0)
{
QByteArray reponse = IL_http->readAll();
QString reponse_lisible = "";
reponse_lisible.append(reponse);
reponse_lisible = reponse_lisible.section("** ",1,1);
reponse_lisible = reponse_lisible.section(" **",0,0);
std::cout << "-=" << reponse_lisible.toStdString() << "=-" << std::endl;
}
else
{
std::cout << "\n\nREPONSE : =-ERREURS-=\n---------" << std::endl;
}
Recuperer_Comptes(); // Call the second request
}
void HTTPChecker::SLOT_IL_httpRequestFinished(int requestId, bool error)
{
if (requestId != IL_httpId)
return;
if (error)
{
IL_NB_erreurs = IL_NB_erreurs + 1;
std::cout << "\n\nERREUR (IL_httpRequestFinished) : " << (IL_http->errorString()).toStdString() << std::endl;
}
}
void HTTPChecker::SLOT_IL_readResponseHeader(const QHttpResponseHeader &responseHeader)
{
if (responseHeader.statusCode() != 200)
{
IL_NB_erreurs = IL_NB_erreurs + 1;
std::cout << "\n\nERREUR (IL_readResponseHeader) : " << (responseHeader.reasonPhrase()).toStdString() << std::endl;
return;
}
QString cookie_value = responseHeader.value("set-cookie");
cookie_value = cookie_value.section(";", 0, 0);
cookie = cookie_value; // Store teh cokie value, for the second request
}
To copy to clipboard, switch view to plain text mode
Second request : the download of a page
void HTTPChecker::Recuperer_Comptes()
{
// header
header.setValue("Host", "courriel");
header.setValue("Cookie", cookie);
header.setContentType("application/x-www-form-urlencoded");
std::cout << "\n\n" << (header.toString()).toStdString() << std::endl;
// request
RC_httpId = RC_http->request(header);
}
void HTTPChecker::SLOT_RC_showPage()
{
if (RC_NB_erreurs == 0)
{
reponse_lisible.append(reponse);
std::cout << reponse_lisible.toStdString() << std::endl;
}
else
{
std::cout << "\n\nREPONSE : =-ERREURS-=\n---------" << std::endl;
}
Quitter();
}
void HTTPChecker::SLOT_RC_httpRequestFinished(int requestId, bool error)
{
if (requestId != RC_httpId)
return;
if (error)
{
RC_NB_erreurs = RC_NB_erreurs + 1;
std::cout << "\n\nERREUR (RC_httpRequestFinished) : " << (RC_http->errorString()).toStdString() << std::endl;
}
}
{
if (responseHeader.statusCode() != 200)
{
RC_NB_erreurs = RC_NB_erreurs + 1;
std::cout << "\n\nERREUR (RC_readResponseHeader) : " << (responseHeader.reasonPhrase()).toStdString() << std::endl;
return;
}
}
void HTTPChecker::Recuperer_Comptes()
{
// header
QHttpRequestHeader header("GET", "/index.php?tg=addon/46/main&idx=aac");
header.setValue("Host", "courriel");
header.setValue("Cookie", cookie);
header.setContentType("application/x-www-form-urlencoded");
std::cout << "\n\n" << (header.toString()).toStdString() << std::endl;
// request
RC_httpId = RC_http->request(header);
}
void HTTPChecker::SLOT_RC_showPage()
{
if (RC_NB_erreurs == 0)
{
QByteArray reponse = RC_http->readAll();
QString reponse_lisible = "";
reponse_lisible.append(reponse);
std::cout << reponse_lisible.toStdString() << std::endl;
}
else
{
std::cout << "\n\nREPONSE : =-ERREURS-=\n---------" << std::endl;
}
Quitter();
}
void HTTPChecker::SLOT_RC_httpRequestFinished(int requestId, bool error)
{
if (requestId != RC_httpId)
return;
if (error)
{
RC_NB_erreurs = RC_NB_erreurs + 1;
std::cout << "\n\nERREUR (RC_httpRequestFinished) : " << (RC_http->errorString()).toStdString() << std::endl;
}
}
void HTTPChecker::SLOT_RC_readResponseHeader(const QHttpResponseHeader &responseHeader)
{
if (responseHeader.statusCode() != 200)
{
RC_NB_erreurs = RC_NB_erreurs + 1;
std::cout << "\n\nERREUR (RC_readResponseHeader) : " << (responseHeader.reasonPhrase()).toStdString() << std::endl;
return;
}
}
To copy to clipboard, switch view to plain text mode
Isn't it good ? 
Another idea :
My account for testing is : "Stagiaire" - "/QDMSy9P".
If we have a look to the headers shown by the navigator, we can see that "/QDMSy9P" becomes "%2FQDMSy9P".
And my request, in the application, send "/QDMSy9P".
I dont think this is a problem, cause when I test with "Stagiaire" - "%2FQDMSy9P", nothing changes.
Bookmarks