-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
36 lines (29 loc) · 1.25 KB
/
Copy pathmain.cpp
File metadata and controls
36 lines (29 loc) · 1.25 KB
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
// Minimal example: GET https://postman-echo.com/get and print the response.
//
// The previous main.cpp referenced a MainWindow class that was never part of
// this project, so it couldn't compile. This is a small, self-contained
// console example that actually exercises the library.
#include "HttpRequestWorker.h"
#include <QCoreApplication>
#include <QDebug>
#include <QEventLoop>
int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
HttpRequestInput input(QStringLiteral("https://postman-echo.com/get?foo1=bar1&foo2=bar2"),
HttpMethod::Get);
HttpRequestWorker worker;
worker.setReadResponseOnError(true);
worker.execute(&input);
QEventLoop loop;
QObject::connect(&worker, &HttpRequestWorker::executionFinished,
[&loop](HttpRequestWorker* w) {
qDebug().noquote() << "status:" << w->statusCode;
qDebug().noquote() << "body:" << w->response;
if (w->errorType != QNetworkReply::NoError)
qDebug().noquote() << "error:" << w->errorStr;
loop.quit();
});
loop.exec();
return worker.errorType == QNetworkReply::NoError ? 0 : 1;
}