You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
807 B
35 lines
807 B
#pragma once
|
|
|
|
#include <QNetworkAccessManager>
|
|
#include <QNetworkRequest>
|
|
#include <QNetworkReply>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
|
|
class HttpClient : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
explicit HttpClient(QObject* parent = nullptr);
|
|
~HttpClient();
|
|
|
|
void get(const QUrl& baseUrl, const QString& token, const QMap<QString, QString>& params);
|
|
void post(const QUrl& baseUrl, const QJsonObject& data, const QString& token = "");
|
|
|
|
bool isFinished() const { return isFinish; }
|
|
void setFinished() { isFinish = true; }
|
|
|
|
signals:
|
|
void finished(const QJsonDocument& json);
|
|
void error(const QString& errTxt);
|
|
|
|
private slots:
|
|
void handleError(QNetworkReply::NetworkError code);
|
|
|
|
private:
|
|
void handleResponse(QNetworkReply* reply);
|
|
|
|
private:
|
|
QNetworkAccessManager* manager;
|
|
|
|
bool isFinish;
|
|
}; |