mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-23 03:10:10 +08:00
update network
This commit is contained in:
parent
eed96b4c0e
commit
bd8a561590
@ -391,6 +391,8 @@ void FluNetwork::sendRequest(QNetworkAccessManager* manager,QNetworkRequest requ
|
||||
QByteArray verb = params->method2String().toUtf8();
|
||||
switch (params->_type) {
|
||||
case NetworkParams::TYPE_FORM:{
|
||||
bool isFormData = !params->_fileMap.isEmpty();
|
||||
if(isFormData){
|
||||
QHttpMultiPart *multiPart = new QHttpMultiPart();
|
||||
multiPart->setContentType(QHttpMultiPart::FormDataType);
|
||||
for (const auto& each : params->_paramMap.toStdMap())
|
||||
@ -415,12 +417,25 @@ void FluNetwork::sendRequest(QNetworkAccessManager* manager,QNetworkRequest requ
|
||||
}
|
||||
reply = manager->sendCustomRequest(request,verb,multiPart);
|
||||
multiPart->setParent(reply);
|
||||
if(!params->_fileMap.isEmpty()){
|
||||
connect(reply,&QNetworkReply::uploadProgress,reply,[callable](qint64 bytesSent, qint64 bytesTotal){
|
||||
if(!callable.isNull() && bytesSent!=0 && bytesTotal!=0){
|
||||
callable->uploadProgress(bytesSent,bytesTotal);
|
||||
Q_EMIT callable->uploadProgress(bytesSent,bytesTotal);
|
||||
}
|
||||
});
|
||||
}else{
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("application/x-www-form-urlencoded"));
|
||||
QString value;
|
||||
for (const auto& each : params->_paramMap.toStdMap())
|
||||
{
|
||||
value += QString("%1=%2").arg(QString(QUrl::toPercentEncoding(each.first)),QString(QUrl::toPercentEncoding(each.second.toString())));
|
||||
value += "&";
|
||||
}
|
||||
if(!params->_paramMap.isEmpty()){
|
||||
value.chop(1);
|
||||
}
|
||||
qDebug()<<value;
|
||||
QByteArray data = value.toUtf8();
|
||||
reply = manager->sendCustomRequest(request,verb,data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user