#ifndef FLUHTTP_H #define FLUHTTP_H #include #include #include #include #include "stdafx.h" class HttpRequest : public QObject{ Q_OBJECT Q_PROPERTY_AUTO(QString,url); Q_PROPERTY_AUTO(QVariant,params); Q_PROPERTY_AUTO(QVariant,headers); Q_PROPERTY_AUTO(QString,method); QML_NAMED_ELEMENT(HttpRequest) public: explicit HttpRequest(QObject *parent = nullptr); ~HttpRequest(){ qDebug()<<"------------析构了"< request); QMap toRequest(const QString& url,const QVariant& params,const QVariant& headers,const QString& method); QString toHttpId(const QMap& map); void addQueryParam(QUrl* url,const QMap& params); void addHeaders(QNetworkRequest* request,const QMap& params); void handleCache(const QString& httpId, const QString& result); QString readCache(const QString& httpId); bool cacheExists(const QString& httpId); QString getCacheFilePath(const QString& httpId); void onStart(QPointer callable); void onFinish(QPointer callable); void onError(QPointer callable,int status,QString errorString,QString result); void onSuccess(QPointer callable,QString result); void onCache(QPointer callable,QString result); void onDownloadProgress(QPointer callable,qint64 recv,qint64 total); void onUploadProgress(QPointer callable,qint64 sent,qint64 total); public: explicit FluHttp(QObject *parent = nullptr); ~FluHttp(); Q_INVOKABLE HttpRequest* newRequest(); Q_INVOKABLE void get2(HttpRequest* request,HttpCallable* callable); //神坑!!! 如果参数使用QVariantMap会有问题,在6.4.3版本中QML一调用就会编译失败。所以改用QMap Q_INVOKABLE void get(QString url,HttpCallable* callable,QMap params= {},QMap headers = {}); Q_INVOKABLE void post(QString url,HttpCallable* callable,QMap params= {},QMap headers = {}); Q_INVOKABLE void postString(QString url,HttpCallable* callable,QString params = "",QMap headers = {}); Q_INVOKABLE void postJson(QString url,HttpCallable* callable,QMap params = {},QMap headers = {}); Q_INVOKABLE void download(QString url,HttpCallable* callable,QString savePath,QMap params = {},QMap headers = {}); Q_INVOKABLE void upload(QString url,HttpCallable* callable,QMap params = {},QMap headers = {}); Q_INVOKABLE qreal breakPointDownloadProgress(QString url,QString savePath,QMap params = {},QMap headers = {}); Q_INVOKABLE void cancel(); private: QList> _cacheReply; }; #endif // FLUHTTP_H