QT 进行http请求头参数填写
参数说明:
第一个是请求的地址。
第二个是待上传的文件
其他的是时间戳或者验证码
QNetworkReply *NetworkManager::postFile(QString urlLoc, QString fileName,QString strcodeNo,QString strtxnNo,QString strsgin)
{
QNetworkRequest request;
// 下面4行代码是用于https 支持
QSslConfiguration conf = QSslConfiguration::defaultConfiguration();
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
conf.setProtocol(QSsl::TlsV1_2);
request.setSslConfiguration(conf);
request.setUrl(QUrl(urlLoc));
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart code;
code.setHeader(QNetworkRequest::ContentDispositionHeader,QVariant("form-data;name=\"code\""));
code.setBody(strcodeNo.toLocal8Bit());
QHttpPart txn;
txn.setHeader(QNetworkRequest::ContentDispositionHeader,QVariant("form-data;name=\"txnNo\""));
txn.setBody(strtxnNo.toLocal8Bit());
QHttpPart sign;
sign.setHeader(QNetworkRequest::ContentDispositionHeader,QVariant("form-data;name=\"sign\""));
sign.setBody(strsgin.toLocal8Bit());
QString files = QString("form-data;name=\"files\";filename=\"%1\";").arg(fileName);
QHttpPart filePart;
filePart.setHeader(QNetworkRequest::ContentDispositionHeader,QVariant(files));
QFile *file = new QFile(fileName);
file->open(QIODevice::ReadOnly);
filePart.setBody(file->readAll());
multiPart->append(code);
multiPart->append(txn);
multiPart->append(sign);
multiPart->append(filePart);
multiPart->setParent(this);
return this->post(request,multiPart);
}