From 0aa5c029d8f8435bf2c23e489c941e1c8b235259 Mon Sep 17 00:00:00 2001 From: LightBase Consultoria em Software Publico Date: Tue, 15 Jul 2014 15:06:13 -0300 Subject: [PATCH] teste de status http --- src/CACIC_comm.h | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/CACIC_comm.h b/src/CACIC_comm.h index 5354bb5..37a7546 100644 --- a/src/CACIC_comm.h +++ b/src/CACIC_comm.h @@ -1,18 +1,47 @@ #ifndef CACIC_COMM_H #define CACIC_COMM_H +#include +#include +#include #include +#include +#include +#include +#include class CacicComm { public: QString comm(QString urlGerente, QString request, QString localFolderName){ -// QString retorno = '0', -// gerColsInfPath = localFolderName + "/gercols.inf", -// chksisInfPath = localFolderName + "/chksis.inf"; - //implementar - return ""; -} + // QString retorno = '0', + // gerColsInfPath = localFolderName + "/gercols.inf", + // chksisInfPath = localFolderName + "/chksis.inf"; + //implementar + return ""; + } + + bool commStatus200(){ + // cria um event-loop temporario + QEventLoop eventLoop; + // "quit()" o event-loop, when the network request "finished()" + QNetworkAccessManager mgr; + QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); + // a requisição HTTP + QNetworkRequest req( QUrl( QString("http://www.google.com.br") ) ); + QNetworkReply *reply = mgr.get(req); + eventLoop.exec(); // sai do looping chamando o "finished()". + QVariant codigoStatus = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ); + QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString(); + if (codigoStatus.isValid()){ + qDebug() << "Status:" << codigoStatus.toInt() << reason; + return true; + }else{ + QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString(); + qDebug() << "Error: Off" << reason; + return false; + } + } }; -- libgit2 0.21.2