From 59f9495f31e7f9013418ff358d103b2cdc46b87d Mon Sep 17 00:00:00 2001 From: zhuzichu Date: Fri, 21 Jul 2023 11:19:30 +0800 Subject: [PATCH] update --- example/qml/App.qml | 1 - example/qml/page/T_Http.qml | 1 + example/src/main.cpp | 4 +++- src/FluHttp.cpp | 12 ++++++++++++ src/FluHttp.h | 2 ++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/example/qml/App.qml b/example/qml/App.qml index f0af5371..1550ac96 100644 --- a/example/qml/App.qml +++ b/example/qml/App.qml @@ -19,7 +19,6 @@ Window { } request.headers["token"] ="yyds" request.headers["os"] ="pc" - console.debug(JSON.stringify(request)) return request } } diff --git a/example/qml/page/T_Http.qml b/example/qml/page/T_Http.qml index 3f50e676..a28962bf 100644 --- a/example/qml/page/T_Http.qml +++ b/example/qml/page/T_Http.qml @@ -43,6 +43,7 @@ FluScrollablePage{ } onError: (status,errorString)=>{ + console.debug(status+"->"+errorString) showError(errorString) } onSuccess: diff --git a/example/src/main.cpp b/example/src/main.cpp index acc279ee..1d51ae86 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include #include @@ -12,7 +14,7 @@ FRAMELESSHELPER_USE_NAMESPACE -int main(int argc, char *argv[]) + int main(int argc, char *argv[]) { //将样式设置为Basic,不然会导致组件显示异常 qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); diff --git a/src/FluHttp.cpp b/src/FluHttp.cpp index c2a773ee..c19a9e42 100644 --- a/src/FluHttp.cpp +++ b/src/FluHttp.cpp @@ -10,6 +10,8 @@ FluHttp::FluHttp(QObject *parent) : QObject{parent} { enabledBreakpointDownload(false); + timeout(15); + retry(3); } Q_INVOKABLE void FluHttp::postString(QString params,QVariantMap headers){ @@ -18,6 +20,8 @@ Q_INVOKABLE void FluHttp::postString(QString params,QVariantMap headers){ HttpClient client; Q_EMIT start(); client.post(_url) + .retry(retry()) + .timeout(timeout()) .bodyWithRaw(request[params].toString().toUtf8()) .headers(request["headers"].toMap()) .onSuccess([=](QString result) { @@ -39,6 +43,8 @@ void FluHttp::post(QVariantMap params,QVariantMap headers){ HttpClient client; Q_EMIT start(); client.post(_url) + .retry(retry()) + .timeout(timeout()) .headers(headers) .bodyWithFormData(request["params"].toMap()) .headers(request["headers"].toMap()) @@ -61,6 +67,8 @@ void FluHttp::postJson(QVariantMap params,QVariantMap headers){ HttpClient client; Q_EMIT start(); client.post(_url) + .retry(retry()) + .timeout(timeout()) .headers(headers) .bodyWithRaw(QJsonDocument::fromVariant(request["params"]).toJson()) .headers(request["headers"].toMap()) @@ -83,6 +91,8 @@ void FluHttp::get(QVariantMap params,QVariantMap headers){ HttpClient client; Q_EMIT start(); client.get(_url) + .retry(retry()) + .timeout(timeout()) .queryParams(request["params"].toMap()) .headers(request["headers"].toMap()) .onSuccess([=](QString result) { @@ -105,6 +115,8 @@ Q_INVOKABLE void FluHttp::download(QString path,QVariantMap params,QVariantMap h HttpClient client; Q_EMIT start(); client.get(_url) + .retry(retry()) + .timeout(timeout()) .download(path) .enabledBreakpointDownload(_enabledBreakpointDownload) .queryParams(request["params"].toMap()) diff --git a/src/FluHttp.h b/src/FluHttp.h index e28e63ab..cbefeef0 100644 --- a/src/FluHttp.h +++ b/src/FluHttp.h @@ -11,6 +11,8 @@ class FluHttp : public QObject Q_OBJECT Q_PROPERTY_AUTO(QString,url); Q_PROPERTY_AUTO(bool,enabledBreakpointDownload) + Q_PROPERTY_AUTO(int,timeout) + Q_PROPERTY_AUTO(int,retry); QML_NAMED_ELEMENT(FluHttp) private: QVariant invokeIntercept(const QVariant& params,const QVariant& headers,const QString& method);