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["os"] ="pc"
console.debug(JSON.stringify(request))
return request
}
}

View File

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

View File

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

View File

@ -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())

View File

@ -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);