diff --git a/example/qml-Qt6/App.qml b/example/qml-Qt6/App.qml index 1a88c8e1..0914ed8d 100644 --- a/example/qml-Qt6/App.qml +++ b/example/qml-Qt6/App.qml @@ -25,7 +25,7 @@ Item { } Component.onCompleted: { - FluNetwork.openLog = true + FluNetwork.openLog = false FluNetwork.setInterceptor(function(param){ param.addHeader("Token","000000000000000000000") }) diff --git a/example/qml-Qt6/page/T_Network.qml b/example/qml-Qt6/page/T_Network.qml index 71baa3cb..0b2c6f6c 100644 --- a/example/qml-Qt6/page/T_Network.qml +++ b/example/qml-Qt6/page/T_Network.qml @@ -280,6 +280,21 @@ FluContentPage{ .go(callable) } } + FluButton{ + implicitWidth: parent.width + implicitHeight: 36 + text: "Open Log" + onClicked: { + text_info.text = "" + FluNetwork.postJson("https://httpbingo.org/post") + .add("name","孙悟空") + .add("age",500) + .add("address","花果山水帘洞") + .openLog(true) + .bind(root) + .go(callable) + } + } FluButton{ implicitWidth: parent.width implicitHeight: 36 diff --git a/example/qml/App.qml b/example/qml/App.qml index 8b57ea9d..4779cbe7 100644 --- a/example/qml/App.qml +++ b/example/qml/App.qml @@ -25,7 +25,7 @@ Item { } Component.onCompleted: { - FluNetwork.openLog = true + FluNetwork.openLog = false FluNetwork.setInterceptor(function(param){ param.addHeader("Token","000000000000000000000") }) diff --git a/example/qml/page/T_Network.qml b/example/qml/page/T_Network.qml index f3310482..1509e53a 100644 --- a/example/qml/page/T_Network.qml +++ b/example/qml/page/T_Network.qml @@ -281,6 +281,21 @@ FluContentPage{ .go(callable) } } + FluButton{ + implicitWidth: parent.width + implicitHeight: 36 + text: "Open Log" + onClicked: { + text_info.text = "" + FluNetwork.postJson("https://httpbingo.org/post") + .add("name","孙悟空") + .add("age",500) + .add("address","花果山水帘洞") + .openLog(true) + .bind(root) + .go(callable) + } + } FluButton{ implicitWidth: parent.width implicitHeight: 36 diff --git a/src/FluNetwork.cpp b/src/FluNetwork.cpp index 7ce096bc..78d6a23b 100644 --- a/src/FluNetwork.cpp +++ b/src/FluNetwork.cpp @@ -54,6 +54,13 @@ int NetworkParams::getRetry(){ return FluNetwork::getInstance()->retry(); } +bool NetworkParams::getOpenLog(){ + if(!_openLog.isNull()){ + return _openLog.toBool(); + } + return FluNetwork::getInstance()->openLog(); +} + DownloadParam::DownloadParam(QObject *parent) : QObject{parent} { @@ -129,6 +136,11 @@ NetworkParams* NetworkParams::bind(QObject* target){ return this; } +NetworkParams* NetworkParams::openLog(QVariant val){ + _openLog = val; + return this; +} + QString NetworkParams::buildCacheKey(){ QJsonObject obj; obj.insert("url",_url); @@ -488,7 +500,7 @@ void FluNetwork::sendRequest(QNetworkAccessManager* manager,QNetworkRequest requ } void FluNetwork::printRequestStartLog(QNetworkRequest request,NetworkParams* params){ - if(!_openLog){ + if(!params->getOpenLog()){ return; } qDebug()<<"<------"<"; @@ -516,7 +528,7 @@ void FluNetwork::printRequestStartLog(QNetworkRequest request,NetworkParams* par } void FluNetwork::printRequestEndLog(QNetworkRequest request,NetworkParams* params,QNetworkReply*& reply,const QString& response){ - if(!_openLog){ + if(!params->getOpenLog()){ return; } qDebug()<<"<------"<"; diff --git a/src/FluNetwork.h b/src/FluNetwork.h index 1ad33466..97316a7e 100644 --- a/src/FluNetwork.h +++ b/src/FluNetwork.h @@ -67,11 +67,13 @@ public: Q_INVOKABLE NetworkParams* setCacheMode(int val); Q_INVOKABLE NetworkParams* toDownload(QString destPath,bool append = false); Q_INVOKABLE NetworkParams* bind(QObject* target); + Q_INVOKABLE NetworkParams* openLog(QVariant val); Q_INVOKABLE void go(NetworkCallable* result); QString buildCacheKey(); QString method2String(); int getTimeout(); int getRetry(); + bool getOpenLog(); public: DownloadParam* _downloadParam = nullptr; QObject* _target = nullptr; @@ -85,6 +87,7 @@ public: QMap _fileMap; int _timeout = -1; int _retry = -1; + QVariant _openLog; int _cacheMode = FluNetworkType::CacheMode::NoCache; };