The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP. More...

QHttpMultiPart类类似于通过HTTP发送的MIME多部分消息

Header: #include <QHttpMultiPart>
qmake: QT += network
Since: Qt 4.8
Inherits: QObject.
List of all members, including inherited members
Public Types

enum ContentType { MixedType, RelatedType, FormDataType, AlternativeType }
Public Functions

QHttpMultiPart(QObject * parent = 0)
QHttpMultiPart(ContentType contentType, QObject * parent = 0)
~QHttpMultiPart()
void append(const QHttpPart & httpPart)
QByteArray boundary() const
void setBoundary(const QByteArray & boundary)
void setContentType(ContentType contentType)
31 public functions inherited from QObject
Additional Inherited Members

1 property inherited from QObject
1 public slot inherited from QObject
2 signals inherited from QObject
1 public variable inherited from QObject
10 static public members inherited from QObject
9 protected functions inherited from QObject
2 protected variables inherited from QObject
Detailed Description详细说明

The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP.

QHttpMultiPart类类似于通过HTTP发送的MIME多部分消息。

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().

QHttpMultiPart类似于MIME多部分消息,如rfc2046中所述,它将通过HTTP发送。多部分消息由任意数量的主体部分组成(请参见QHttpPart),它们由一个唯一的边界分隔开。QHttpMultiPart的边界由字符串“boundary_o.oOo.”后跟随机字符构成,并提供足够的唯一性以确保它不会出现在部件本身内部。如果需要,仍然可以通过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.

RFC 2046和其他描述的多部分子类型的已知内容类型列表。

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().

Member Function Documentation成员函数文档

QHttpMultiPart::QHttpMultiPart(QObject * parent = 0)
Constructs a QHttpMultiPart with content type MixedType and sets parent as the parent object.

构造内容类型为MixedType的QHttpMultiPart并将parent设置为父对象。

See also QHttpMultiPart::ContentType.

QHttpMultiPart::QHttpMultiPart(ContentType contentType, QObject * parent = 0)
Constructs a QHttpMultiPart with content type contentType and sets parent as the parent object.

构造内容类型为contentType的QHttpMultiPart并将parent设置为父对象。

See also QHttpMultiPart::ContentType.

QHttpMultiPart::~QHttpMultiPart()
Destroys the multipart.

void QHttpMultiPart::append(const QHttpPart & httpPart)
Appends httpPart to this multipart.

将httpPart附加到后面。

QByteArray QHttpMultiPart::boundary() const
returns the boundary.

返回边界。

See also setBoundary().

void QHttpMultiPart::setBoundary(const QByteArray & boundary)
Sets the boundary to boundary.

将边界设置为边界。

Usually, you do not need to generate a boundary yourself; upon construction the boundary is initiated with the string "boundary_.oOo._" followed by random characters, and provides enough uniqueness to make sure it does not occur inside the parts itself.

通常,您不需要自己生成一个边界;在构造时,边界以字符串“boundary_.oOo._”开头,后跟随机字符,并提供足够的唯一性以确保它不会出现在部件内部。

See also boundary().

void QHttpMultiPart::setContentType(ContentType contentType)
Sets the content type to contentType. The content type will be used in the HTTP header section when sending the multipart message via QNetworkAccessManager::post(). In case you want to use a multipart subtype not contained in QHttpMultiPart::ContentType, you can add the "Content-Type" header field to the QNetworkRequest by hand, and then use this request together with the multipart message for posting.

将内容类型设置为contentType。通过QNetworkAccessManager::post()发送多部分消息时,将在HTTP头部分使用内容类型。如果您想使用QHttpMultiPart::ContentType中没有包含的多部分子类型,您可以手动将“Content Type”头字段添加到QNetworkRequest中,然后将此请求与多部分消息一起用于发布。

See also QHttpMultiPart::ContentType and QNetworkAccessManager::post().

另请参见QHttpMultiPart::ContentType和QNetworkAccessManager::post()。

posted on 2020-09-27 16:22  七星落地  阅读(508)  评论(0编辑  收藏  举报