QT 调用HTTP post命令上传时耗时相比poatman,apifox等软件较久
并且上传数据较小时,速度反而慢,当上传速度大于一定数值时速度就变快了200多ms
不开加速器时速度也慢,开了加速器也变块了,请问大家是啥原因咋解决呀
/*
功能说明:post请求
参数说明:key - 加密的密钥
data - 加密的参数
返 回:无
*/
void GaodePost::PostRequest(QString key,QString data)
{
QJsonObject dataobj; //构建json对象dataobj
dataobj.insert("key",key);
dataobj.insert("data",data);
QJsonDocument document;
document.setObject(dataobj);
QByteArray byte_array = document.toJson(QJsonDocument::Compact); //类型转换
//http请求
QNetworkRequest request1;
QNetworkAccessManager nam;
connect(&nam, &QNetworkAccessManager::finished, this, &GaodePost::receiveGaodePostReply);
request1.setUrl(QUrl("http://123.12.365.152/接口名")); //要请求的网址
//请求头token设置
request1.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json;charset=utf-8"));
QString token = "xxxxxxxxxxxxxxxxxxxxxxxx";
QString token_headerData = token;
request1.setRawHeader("token",token_headerData.toLocal8Bit());
QNetworkReply* reply = nam.post(request1, byte_array); //post请求头+传输的数据
//开启事件循环,直到请求完成
QEventLoop loop;
connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
loop.exec();
}
//接收请求返回的数据
QString GaodePost::receiveGaodePostReply(QNetworkReply *reply)
{
QString res = reply->readAll();
return res;
}