我正在尝试使用Qt的QNetworkAccessManager类使用POST方法将图像上传到apache服务器。我没有得到的是,如何为图像设置合适的QNetworkRequest :: ContentTypeHeader和QNetworkRequest :: ContentLengthHeader?如果ContentTypeHeader是“multipart / form-data”,那么边界应该设置为什么?
示例代码:
data = new QFile("/home/darshan/aindra/1.png", this);
if (data->open(QIODevice::ReadOnly))
{
manager = new QNetworkAccessManager();
req.setUrl(QUrl(upload_url));
//space for req.setHeader() - contenttypeheader
//space for req.setHeader() - contentlengthheader
//reply = manager->post(req, QByteArray);
connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(requestFinished(QNetworkReply*)));
connect(reply, SIGNAL(uploadProgress(qint64, qint64)), SLOT(uploadProgress(qint64, qint64)));
}
else
{
qDebug() << "Could not open file to FTP";
}
答案 0 :(得分:2)
自Qt 4.8起,您可以使用QHttpMultipart
上传QNetworkAccessManager
的文件。