#ifndef FLUHTTP_H #define FLUHTTP_H #include #include #include #include #include "stdafx.h" class FluHttp : public QObject { Q_OBJECT Q_PROPERTY_AUTO(int,retry); Q_PROPERTY_AUTO(int,timeout) QML_NAMED_ELEMENT(FluHttp) private: QVariant invokeIntercept(const QVariant& params,const QVariant& headers,const QString& method); void handleReply(QNetworkReply* reply); void addQueryParam(QUrl* url,const QMap& params); void addHeaders(QNetworkRequest* request,const QMap& params); void onStart(const QJSValue& callable); void onFinish(const QJSValue& callable); void onError(const QJSValue& callable,int status,QString errorString); void onSuccess(const QJSValue& callable,QString result); void onDownloadProgress(const QJSValue& callable,qint64 recv, qint64 total); public: explicit FluHttp(QObject *parent = nullptr); ~FluHttp(); //神坑!!! 如果参数使用QVariantMap会有问题,在6.4.3版本中QML一调用就会编译失败。所以改用QMap Q_INVOKABLE void get(QString url,QJSValue callable,QMap = {},QMap headers = {}); Q_INVOKABLE void post(QString url,QJSValue callable,QMap = {},QMap headers = {}); Q_INVOKABLE void postString(QString url,QJSValue callable,QString params = "",QMap headers = {}); Q_INVOKABLE void postJson(QString url,QJSValue callable,QMap params = {},QMap headers = {}); Q_INVOKABLE void download(QString url,QJSValue callable,QString filePath,QMap params = {},QMap headers = {}); Q_INVOKABLE void cancel(); private: QList> _cache; }; #endif // FLUHTTP_H