mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-01-22 20:04:32 +08:00
FluNetwork add Head Request
This commit is contained in:
parent
33c203fcb3
commit
6c86e61916
@ -64,6 +64,20 @@ FluContentPage{
|
||||
.go(callable)
|
||||
}
|
||||
}
|
||||
FluButton{
|
||||
implicitWidth: parent.width
|
||||
implicitHeight: 36
|
||||
text: "Head"
|
||||
onClicked: {
|
||||
text_info.text = ""
|
||||
FluNetwork.head("https://httpbingo.org/head")
|
||||
.addQuery("name","孙悟空")
|
||||
.addQuery("age",500)
|
||||
.addQuery("address","花果山水帘洞")
|
||||
.bind(root)
|
||||
.go(callable)
|
||||
}
|
||||
}
|
||||
FluButton{
|
||||
implicitWidth: parent.width
|
||||
implicitHeight: 36
|
||||
|
@ -65,6 +65,20 @@ FluContentPage{
|
||||
.go(callable)
|
||||
}
|
||||
}
|
||||
FluButton{
|
||||
implicitWidth: parent.width
|
||||
implicitHeight: 36
|
||||
text: "Head"
|
||||
onClicked: {
|
||||
text_info.text = ""
|
||||
FluNetwork.head("https://httpbingo.org/head")
|
||||
.addQuery("name","孙悟空")
|
||||
.addQuery("age",500)
|
||||
.addQuery("address","花果山水帘洞")
|
||||
.bind(root)
|
||||
.go(callable)
|
||||
}
|
||||
}
|
||||
FluButton{
|
||||
implicitWidth: parent.width
|
||||
implicitHeight: 36
|
||||
|
@ -227,23 +227,26 @@ void FluNetwork::handle(NetworkParams* params,NetworkCallable* c){
|
||||
disconnect(conn_quit);
|
||||
}
|
||||
QString response;
|
||||
if(reply->isOpen()){
|
||||
response = QString::fromUtf8(reply->readAll());
|
||||
if(params->_method == NetworkParams::METHOD_HEAD){
|
||||
response = headerList2String(reply->rawHeaderPairs());
|
||||
}else{
|
||||
if(reply->isOpen()){
|
||||
response = QString::fromUtf8(reply->readAll());
|
||||
}
|
||||
}
|
||||
QNetworkReply::NetworkError error = reply->error();
|
||||
if(error == QNetworkReply::NoError){
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if(httpStatus == 200){
|
||||
if(!callable.isNull()){
|
||||
if(params->_cacheMode != FluNetworkType::CacheMode::NoCache){
|
||||
saveResponse(cacheKey,response);
|
||||
}
|
||||
callable->success(response);
|
||||
callable->success(response);
|
||||
}
|
||||
printRequestEndLog(request,params,reply,response);
|
||||
break;
|
||||
}else{
|
||||
if(i == params->getRetry()-1){
|
||||
if(!callable.isNull()){
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if(params->_cacheMode == FluNetworkType::CacheMode::RequestFailedReadCache && cacheExists(cacheKey)){
|
||||
if(!callable.isNull()){
|
||||
callable->cache(readCache(cacheKey));
|
||||
@ -401,6 +404,14 @@ QString FluNetwork::getCacheFilePath(const QString& key){
|
||||
return cacheDir.absoluteFilePath(key);
|
||||
}
|
||||
|
||||
QString FluNetwork::headerList2String(const QList<QNetworkReply::RawHeaderPair>& data){
|
||||
QJsonObject object;
|
||||
for (auto it = data.constBegin(); it != data.constEnd(); ++it) {
|
||||
object.insert(QString(it->first),QString(it->second));
|
||||
}
|
||||
return QJsonDocument(object).toJson(QJsonDocument::Compact);
|
||||
}
|
||||
|
||||
QString FluNetwork::map2String(const QMap<QString, QVariant>& map){
|
||||
QStringList parameters;
|
||||
for (auto it = map.constBegin(); it != map.constEnd(); ++it) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <QJsonValue>
|
||||
#include <QJSValue>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include "Def.h"
|
||||
#include "stdafx.h"
|
||||
#include "singleton.h"
|
||||
@ -135,6 +136,7 @@ private:
|
||||
bool cacheExists(const QString& key);
|
||||
QString getCacheFilePath(const QString& key);
|
||||
QString map2String(const QMap<QString, QVariant>& map);
|
||||
QString headerList2String(const QList<QNetworkReply::RawHeaderPair>& data);
|
||||
void printRequestStartLog(QNetworkRequest request,NetworkParams* params);
|
||||
void printRequestEndLog(QNetworkRequest request,NetworkParams* params,QNetworkReply*& reply,const QString& response);
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user