2023-07-20 18:26:47 +08:00
|
|
|
#ifndef FLUHTTP_H
|
|
|
|
#define FLUHTTP_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QtQml/qqml.h>
|
2023-07-23 20:44:43 +08:00
|
|
|
#include <QFile>
|
2023-07-20 18:26:47 +08:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
class FluHttp : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY_AUTO(QString,url);
|
|
|
|
QML_NAMED_ELEMENT(FluHttp)
|
|
|
|
private:
|
|
|
|
QVariant invokeIntercept(const QVariant& params,const QVariant& headers,const QString& method);
|
2023-07-21 18:58:09 +08:00
|
|
|
void handleReply(QNetworkReply* reply);
|
2023-07-23 20:44:43 +08:00
|
|
|
void addQueryParam(QUrl* url,const QMap<QString, QVariant>& params);
|
|
|
|
void addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>& params);
|
2023-07-20 18:26:47 +08:00
|
|
|
public:
|
|
|
|
explicit FluHttp(QObject *parent = nullptr);
|
2023-07-21 18:58:09 +08:00
|
|
|
~FluHttp();
|
2023-07-20 18:26:47 +08:00
|
|
|
Q_SIGNAL void start();
|
|
|
|
Q_SIGNAL void finish();
|
|
|
|
Q_SIGNAL void error(int status,QString errorString);
|
|
|
|
Q_SIGNAL void success(QString result);
|
2023-07-20 21:54:45 +08:00
|
|
|
Q_SIGNAL void downloadProgress(qint64 recv, qint64 total);
|
2023-07-20 18:26:47 +08:00
|
|
|
Q_INVOKABLE void get(QVariantMap params = {},QVariantMap headers = {});
|
|
|
|
Q_INVOKABLE void post(QVariantMap params = {},QVariantMap headers = {});
|
|
|
|
Q_INVOKABLE void download(QString path,QVariantMap params = {},QVariantMap headers = {});
|
2023-07-21 18:58:09 +08:00
|
|
|
Q_INVOKABLE void cancel();
|
2023-07-23 20:44:43 +08:00
|
|
|
private:
|
|
|
|
QList<QPointer<QNetworkReply>> _cache;
|
2023-07-20 18:26:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FLUHTTP_H
|