1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <QtGui>
#include <QtNetwork>
#include <QHttp>
#include <QtXml>
#include <QtDebug>
#include "tool.h"
void Tool::on_pushButton_connection_clicked()
{
http = new QHttp(this); // variable de la class Http
connect(&http, SIGNAL(done(bool)), this, SLOT(affiche(bool)));
connect(&http, SIGNAL(requestFinished(int, bool)), this, SLOT(fin(int, bool)));
QHttpRequestHeader header("POST", "/page.php");
header.setValue("Host", "www.site.fr");
http->setHost("www.site.fr");
header.setValue( "User-Agent", "User Agent");
header.setContentType("application/x-www-form-urlencoded");
QString PostVariable = "username=";
PostVariable+=uiConfig.lineEdit_2->text();
PostVariable+="&password=";
PostVariable+=QCryptographicHash::hash(uiConfig.lineEdit->text().toUtf8(),QCryptographicHash::Sha1).toHex();
PostVariable+=uiConfig.lineEdit->text();
http->request(header,PostVariable.toUtf8());
}
void Tool::fin(int _id, bool _error)
{
if(_error)
QMessageBox::information(0, "Fin", QString().setNum(http->error()));
}
void Tool::affiche(bool)
{
QDomDocument infos;
QString errorStr;
int errorLine;
int errorColumn;
QByteArray content = http->readAll();
if (!infos.setContent(content, true, &errorStr, &errorLine, &errorColumn))
{
qDebug() << "Error parsing session file";
qDebug() << content; return;
}
QDomElement element = infos.documentElement();
for(QDomNode n = element.firstChild();
!n.isNull();
n = n.nextSibling())
{
QDomElement e = n.toElement();
qDebug() << e.tagName() << e.text();
QMessageBox::information(0, tr("Programme"), e.tagName());
}
} |
Partager