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
| void ConnexionManager::connectToWebService(QString host, int port, QString path, vector <QStringList> paramsList)
{
m_bError = false;
httpRequest = "";
logSingleton->writeText(QString("-------- %1 : Préparation de la requête de récupération de la date à envoyer\n")
.arg(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss")));
// formater la chaine à envoyer
int i = 0;
int listParamSize = paramsList.size()-1;
while(i <= listParamSize)
{
if(0 < i)
{
httpRequest += "&";
}
httpRequest += QString(paramsList[i].at(0).toLocal8Bit().constData())+"="+QUrl::toPercentEncoding(QString(paramsList[i].at(1).toLocal8Bit().constData()));
++i;
}
// invoquer le service web
QHttpRequestHeader header("POST", host);
header.setValue("HOST", host);
header.setValue("Cache-Control", "no-cache");
header.setContentType("application/x-www-form-urlencoded");
header.setContentLength(httpRequest.length());
// attribuer le host selon le parametre de connection
if( port > 0)
{
if (useHttps)
http->setHost(host, QHttp::ConnectionModeHttps, port);
else
http->setHost(host, QHttp::ConnectionModeHttp, port);
}
else
{
if (useHttps)
http->setHost(host, QHttp::ConnectionModeHttps);
else
http->setHost(host, QHttp::ConnectionModeHttp);
}
logSingleton->writeText(QString("-------- %1 : Envoi de la requête récupération de la date au serveur [%2] avec les paramètres : Requete=%3-Méthode=%4-Port=%5\n")
.arg(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss"), host, httpRequest, path, QString::number(port)));
if(0 < i)
this->idVerify = this->http->request(header, httpRequest.toUtf8());
else
this->idVerify = this->http->request(header);
logSingleton->writeText(QString("-------- %1 : Id Requete=%2\n")
.arg(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss"), QString::number(this->idVerify)));
this->http->close();
} |
Partager