mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-23 11:17:15 +08:00
add delete method for http
This commit is contained in:
parent
e631465231
commit
5a49ffb7e0
@ -127,6 +127,15 @@ FluContentPage{
|
|||||||
http.postString(request,callable)
|
http.postString(request,callable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
FluButton{
|
||||||
|
implicitWidth: parent.width
|
||||||
|
implicitHeight: 36
|
||||||
|
text: "Delete请求"
|
||||||
|
onClicked: {
|
||||||
|
var request = http.newRequest("https://httpbingo.org/delete")
|
||||||
|
http.deleteResource(request,callable)
|
||||||
|
}
|
||||||
|
}
|
||||||
FluProgressButton{
|
FluProgressButton{
|
||||||
id:btn_download
|
id:btn_download
|
||||||
implicitWidth: parent.width
|
implicitWidth: parent.width
|
||||||
|
@ -479,6 +479,62 @@ void FluHttp::upload(HttpRequest* request,HttpCallable* callable){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FluHttp::deleteResource(HttpRequest* request,HttpCallable* callable)
|
||||||
|
{
|
||||||
|
request->method("deleteResource");
|
||||||
|
auto requestMap = request->toMap();
|
||||||
|
auto httpId = request->httpId();
|
||||||
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
|
QThreadPool::globalInstance()->start([=](){
|
||||||
|
onStart(callable);
|
||||||
|
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
|
||||||
|
onCache(callable,readCache(httpId));
|
||||||
|
}
|
||||||
|
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
||||||
|
onCache(callable,readCache(httpId));
|
||||||
|
onFinish(callable,request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QNetworkAccessManager manager;
|
||||||
|
manager.setTransferTimeout(timeout());
|
||||||
|
for (int i = 0; i < retry(); ++i) {
|
||||||
|
QUrl url(request->url());
|
||||||
|
addQueryParam(&url,data["params"].toMap());
|
||||||
|
QNetworkRequest req(url);
|
||||||
|
addHeaders(&req,data["headers"].toMap());
|
||||||
|
QEventLoop loop;
|
||||||
|
QNetworkReply* reply = manager.deleteResource(req);
|
||||||
|
_cacheReply.append(reply);
|
||||||
|
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
||||||
|
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
|
||||||
|
loop.exec();
|
||||||
|
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
QString errorString = reply->errorString();
|
||||||
|
bool isSuccess = reply->error() == QNetworkReply::NoError;
|
||||||
|
QString result = QString::fromUtf8(reply->readAll());
|
||||||
|
if (isSuccess) {
|
||||||
|
handleCache(httpId,result);
|
||||||
|
onSuccess(callable,result);
|
||||||
|
break;
|
||||||
|
}else{
|
||||||
|
if(i == retry()-1){
|
||||||
|
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(httpId)){
|
||||||
|
onCache(callable,readCache(httpId));
|
||||||
|
}
|
||||||
|
onError(callable,status,errorString,result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QNetworkReply::NetworkError error = reply->error();
|
||||||
|
if(error == QNetworkReply::OperationCanceledError){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
reply->deleteLater();
|
||||||
|
reply = nullptr;
|
||||||
|
}
|
||||||
|
onFinish(callable,request);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
QVariant FluHttp::invokeIntercept(QMap<QString, QVariant> request){
|
QVariant FluHttp::invokeIntercept(QMap<QString, QVariant> request){
|
||||||
if(!FluApp::getInstance()->httpInterceptor()){
|
if(!FluApp::getInstance()->httpInterceptor()){
|
||||||
return request;
|
return request;
|
||||||
|
@ -69,6 +69,7 @@ public:
|
|||||||
Q_INVOKABLE void postJson(HttpRequest* request,HttpCallable* callable);
|
Q_INVOKABLE void postJson(HttpRequest* request,HttpCallable* callable);
|
||||||
Q_INVOKABLE void download(HttpRequest* request,HttpCallable* callable);
|
Q_INVOKABLE void download(HttpRequest* request,HttpCallable* callable);
|
||||||
Q_INVOKABLE void upload(HttpRequest* request,HttpCallable* callable);
|
Q_INVOKABLE void upload(HttpRequest* request,HttpCallable* callable);
|
||||||
|
Q_INVOKABLE void deleteResource(HttpRequest* request,HttpCallable* callable);
|
||||||
Q_INVOKABLE qreal getBreakPointProgress(HttpRequest* request);
|
Q_INVOKABLE qreal getBreakPointProgress(HttpRequest* request);
|
||||||
Q_INVOKABLE void cancel();
|
Q_INVOKABLE void cancel();
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user