QHttpMultiPart Class
The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP. More...
| Header: | #include <QHttpMultiPart> |
| qmake: | QT += network |
| Since: | Qt 4.8 |
| Inherits: | QObject |
This class was introduced in Qt 4.8.
Public Types
| enum | ContentType { MixedType, RelatedType, FormDataType, AlternativeType } |
Detailed Description
The QHttpMultiPart resembles a MIME multipart message, as described in RFC 2046, which is to be sent over HTTP. A multipart message consists of an arbitrary number of body parts (see QHttpPart), which are separated by a unique boundary. The boundary of the QHttpMultiPart is constructed with the string "boundary_.oOo._" followed by random characters, and provides enough uniqueness to make sure it does not occur inside the parts itself. If desired, the boundary can still be set via setBoundary().
As an example, consider the following code snippet, which constructs a multipart message containing a text part followed by an image part:
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart textPart; textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\"")); textPart.setBody("my text"); QHttpPart imagePart; imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\"")); QFile *file = new QFile("image.jpg"); file->open(QIODevice::ReadOnly); imagePart.setBodyDevice(file); file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart multiPart->append(textPart); multiPart->append(imagePart); QUrl url("http://my.server.tld"); QNetworkRequest request(url); QNetworkAccessManager manager; QNetworkReply *reply = manager.post(request, multiPart); multiPart->setParent(reply); // delete the multiPart with the reply // here connect signals etc.
See also QHttpPart and QNetworkAccessManager::post().
Member Type Documentation
enum QHttpMultiPart::ContentType
List of known content types for a multipart subtype as described in RFC 2046 and others.
| Constant | Value | Description |
|---|---|---|
QHttpMultiPart::MixedType | 0 | corresponds to the "multipart/mixed" subtype, meaning the body parts are independent of each other, as described in RFC 2046. |
QHttpMultiPart::RelatedType | 1 | corresponds to the "multipart/related" subtype, meaning the body parts are related to each other, as described in RFC 2387. |
QHttpMultiPart::FormDataType | 2 | corresponds to the "multipart/form-data" subtype, meaning the body parts contain form elements, as described in RFC 2388. |
QHttpMultiPart::AlternativeType | 3 | corresponds to the "multipart/alternative" subtype, meaning the body parts are alternative representations of the same information, as described in RFC 2046. |
See also setContentType().