我正在尝试使用 POST 方法使用 Qt 的 QNetworkAccessManager 类将图像上传到 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";
}