This commit is contained in:
zhuzichu 2023-07-21 11:19:30 +08:00
parent d014997d52
commit 59f9495f31
5 changed files with 18 additions and 2 deletions

View File

@ -19,7 +19,6 @@ Window {
} }
request.headers["token"] ="yyds" request.headers["token"] ="yyds"
request.headers["os"] ="pc" request.headers["os"] ="pc"
console.debug(JSON.stringify(request))
return request return request
} }
} }

View File

@ -43,6 +43,7 @@ FluScrollablePage{
} }
onError: onError:
(status,errorString)=>{ (status,errorString)=>{
console.debug(status+"->"+errorString)
showError(errorString) showError(errorString)
} }
onSuccess: onSuccess:

View File

@ -3,6 +3,8 @@
#include <QQmlContext> #include <QQmlContext>
#include <QDir> #include <QDir>
#include <QQuickWindow> #include <QQuickWindow>
#include <QNetworkProxy>
#include <QSslConfiguration>
#include <QProcess> #include <QProcess>
#include <FramelessHelper/Quick/framelessquickmodule.h> #include <FramelessHelper/Quick/framelessquickmodule.h>
#include <FramelessHelper/Core/private/framelessconfig_p.h> #include <FramelessHelper/Core/private/framelessconfig_p.h>

View File

@ -10,6 +10,8 @@ FluHttp::FluHttp(QObject *parent)
: QObject{parent} : QObject{parent}
{ {
enabledBreakpointDownload(false); enabledBreakpointDownload(false);
timeout(15);
retry(3);
} }
Q_INVOKABLE void FluHttp::postString(QString params,QVariantMap headers){ Q_INVOKABLE void FluHttp::postString(QString params,QVariantMap headers){
@ -18,6 +20,8 @@ Q_INVOKABLE void FluHttp::postString(QString params,QVariantMap headers){
HttpClient client; HttpClient client;
Q_EMIT start(); Q_EMIT start();
client.post(_url) client.post(_url)
.retry(retry())
.timeout(timeout())
.bodyWithRaw(request[params].toString().toUtf8()) .bodyWithRaw(request[params].toString().toUtf8())
.headers(request["headers"].toMap()) .headers(request["headers"].toMap())
.onSuccess([=](QString result) { .onSuccess([=](QString result) {
@ -39,6 +43,8 @@ void FluHttp::post(QVariantMap params,QVariantMap headers){
HttpClient client; HttpClient client;
Q_EMIT start(); Q_EMIT start();
client.post(_url) client.post(_url)
.retry(retry())
.timeout(timeout())
.headers(headers) .headers(headers)
.bodyWithFormData(request["params"].toMap()) .bodyWithFormData(request["params"].toMap())
.headers(request["headers"].toMap()) .headers(request["headers"].toMap())
@ -61,6 +67,8 @@ void FluHttp::postJson(QVariantMap params,QVariantMap headers){
HttpClient client; HttpClient client;
Q_EMIT start(); Q_EMIT start();
client.post(_url) client.post(_url)
.retry(retry())
.timeout(timeout())
.headers(headers) .headers(headers)
.bodyWithRaw(QJsonDocument::fromVariant(request["params"]).toJson()) .bodyWithRaw(QJsonDocument::fromVariant(request["params"]).toJson())
.headers(request["headers"].toMap()) .headers(request["headers"].toMap())
@ -83,6 +91,8 @@ void FluHttp::get(QVariantMap params,QVariantMap headers){
HttpClient client; HttpClient client;
Q_EMIT start(); Q_EMIT start();
client.get(_url) client.get(_url)
.retry(retry())
.timeout(timeout())
.queryParams(request["params"].toMap()) .queryParams(request["params"].toMap())
.headers(request["headers"].toMap()) .headers(request["headers"].toMap())
.onSuccess([=](QString result) { .onSuccess([=](QString result) {
@ -105,6 +115,8 @@ Q_INVOKABLE void FluHttp::download(QString path,QVariantMap params,QVariantMap h
HttpClient client; HttpClient client;
Q_EMIT start(); Q_EMIT start();
client.get(_url) client.get(_url)
.retry(retry())
.timeout(timeout())
.download(path) .download(path)
.enabledBreakpointDownload(_enabledBreakpointDownload) .enabledBreakpointDownload(_enabledBreakpointDownload)
.queryParams(request["params"].toMap()) .queryParams(request["params"].toMap())

View File

@ -11,6 +11,8 @@ class FluHttp : public QObject
Q_OBJECT Q_OBJECT
Q_PROPERTY_AUTO(QString,url); Q_PROPERTY_AUTO(QString,url);
Q_PROPERTY_AUTO(bool,enabledBreakpointDownload) Q_PROPERTY_AUTO(bool,enabledBreakpointDownload)
Q_PROPERTY_AUTO(int,timeout)
Q_PROPERTY_AUTO(int,retry);
QML_NAMED_ELEMENT(FluHttp) QML_NAMED_ELEMENT(FluHttp)
private: private:
QVariant invokeIntercept(const QVariant& params,const QVariant& headers,const QString& method); QVariant invokeIntercept(const QVariant& params,const QVariant& headers,const QString& method);