update network

This commit is contained in:
zhuzichu 2023-12-06 18:23:51 +08:00
parent eed96b4c0e
commit bd8a561590

View File

@ -391,6 +391,8 @@ void FluNetwork::sendRequest(QNetworkAccessManager* manager,QNetworkRequest requ
QByteArray verb = params->method2String().toUtf8(); QByteArray verb = params->method2String().toUtf8();
switch (params->_type) { switch (params->_type) {
case NetworkParams::TYPE_FORM:{ case NetworkParams::TYPE_FORM:{
bool isFormData = !params->_fileMap.isEmpty();
if(isFormData){
QHttpMultiPart *multiPart = new QHttpMultiPart(); QHttpMultiPart *multiPart = new QHttpMultiPart();
multiPart->setContentType(QHttpMultiPart::FormDataType); multiPart->setContentType(QHttpMultiPart::FormDataType);
for (const auto& each : params->_paramMap.toStdMap()) for (const auto& each : params->_paramMap.toStdMap())
@ -415,12 +417,25 @@ void FluNetwork::sendRequest(QNetworkAccessManager* manager,QNetworkRequest requ
} }
reply = manager->sendCustomRequest(request,verb,multiPart); reply = manager->sendCustomRequest(request,verb,multiPart);
multiPart->setParent(reply); multiPart->setParent(reply);
if(!params->_fileMap.isEmpty()){
connect(reply,&QNetworkReply::uploadProgress,reply,[callable](qint64 bytesSent, qint64 bytesTotal){ connect(reply,&QNetworkReply::uploadProgress,reply,[callable](qint64 bytesSent, qint64 bytesTotal){
if(!callable.isNull() && bytesSent!=0 && bytesTotal!=0){ 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; break;
} }