Commit 0aa5c029d8f8435bf2c23e489c941e1c8b235259
1 parent
eeb27654
Exists in
master
teste de status http
Showing
1 changed file
with
35 additions
and
6 deletions
Show diff stats
src/CACIC_comm.h
1 | #ifndef CACIC_COMM_H | 1 | #ifndef CACIC_COMM_H |
2 | #define CACIC_COMM_H | 2 | #define CACIC_COMM_H |
3 | 3 | ||
4 | +#include <QCoreApplication> | ||
5 | +#include <QDebug> | ||
6 | +#include <QUrlQuery> | ||
4 | #include <QString> | 7 | #include <QString> |
8 | +#include <QtNetwork/QNetworkAccessManager> | ||
9 | +#include <QtNetwork/QNetworkRequest> | ||
10 | +#include <QtNetwork/QNetworkReply> | ||
11 | +#include <QUrl> | ||
5 | 12 | ||
6 | class CacicComm { | 13 | class CacicComm { |
7 | public: | 14 | public: |
8 | 15 | ||
9 | QString comm(QString urlGerente, QString request, QString localFolderName){ | 16 | QString comm(QString urlGerente, QString request, QString localFolderName){ |
10 | -// QString retorno = '0', | ||
11 | -// gerColsInfPath = localFolderName + "/gercols.inf", | ||
12 | -// chksisInfPath = localFolderName + "/chksis.inf"; | ||
13 | - //implementar | ||
14 | - return ""; | ||
15 | -} | 17 | + // QString retorno = '0', |
18 | + // gerColsInfPath = localFolderName + "/gercols.inf", | ||
19 | + // chksisInfPath = localFolderName + "/chksis.inf"; | ||
20 | + //implementar | ||
21 | + return ""; | ||
22 | + } | ||
23 | + | ||
24 | + bool commStatus200(){ | ||
25 | + // cria um event-loop temporario | ||
26 | + QEventLoop eventLoop; | ||
27 | + // "quit()" o event-loop, when the network request "finished()" | ||
28 | + QNetworkAccessManager mgr; | ||
29 | + QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); | ||
30 | + // a requisição HTTP | ||
31 | + QNetworkRequest req( QUrl( QString("http://www.google.com.br") ) ); | ||
32 | + QNetworkReply *reply = mgr.get(req); | ||
33 | + eventLoop.exec(); // sai do looping chamando o "finished()". | ||
34 | + QVariant codigoStatus = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ); | ||
35 | + QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString(); | ||
36 | + if (codigoStatus.isValid()){ | ||
37 | + qDebug() << "Status:" << codigoStatus.toInt() << reason; | ||
38 | + return true; | ||
39 | + }else{ | ||
40 | + QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString(); | ||
41 | + qDebug() << "Error: Off" << reason; | ||
42 | + return false; | ||
43 | + } | ||
44 | + } | ||
16 | 45 | ||
17 | }; | 46 | }; |
18 | 47 |