Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QHttpMultiPart Class

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

Header:#include <QHttpMultiPart>
Since: Qt 4.8
Inherits:QObject

Public Types

enumContentType { MixedType, RelatedType, FormDataType, AlternativeType }

Public Functions

QHttpMultiPart(QObject * parent = 0)
QHttpMultiPart(ContentType contentType, QObject * parent = 0)
~QHttpMultiPart()
voidappend(const QHttpPart & httpPart)
QByteArrayboundary() const
voidsetBoundary(const QByteArray & boundary)
voidsetContentType(ContentType contentType)
  • 29 public functions inherited fromQObject

Additional Inherited Members

  • 1 property inherited fromQObject
  • 1 public slot inherited fromQObject
  • 1 signal inherited fromQObject
  • 7 static public members inherited fromQObject
  • 8 protected functions inherited fromQObject

Detailed Description

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

TheQHttpMultiPart 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 (seeQHttpPart), which are separated by a unique boundary. The boundary of theQHttpMultiPart 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 viasetBoundary().

As an example, consider the following code snippet, which constructs a multipart message containing a text part followed by an image part:

QHttpMultiPart*multiPart=newQHttpMultiPart(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=newQFile("image.jpg");file->open(QIODevice::ReadOnly);imagePart.setBodyDevice(file);file->setParent(multiPart);// we cannot delete the file now, so delete it with the multiPartmultiPart->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 alsoQHttpPart andQNetworkAccessManager::post().

Member Type Documentation

enum QHttpMultiPart::ContentType

List of known content types for a multipart subtype as described in RFC 2046 and others.

ConstantValueDescription
QHttpMultiPart::MixedType0corresponds to the "multipart/mixed" subtype, meaning the body parts are independent of each other, as described in RFC 2046.
QHttpMultiPart::RelatedType1corresponds to the "multipart/related" subtype, meaning the body parts are related to each other, as described in RFC 2387.
QHttpMultiPart::FormDataType2corresponds to the "multipart/form-data" subtype, meaning the body parts contain form elements, as described in RFC 2388.
QHttpMultiPart::AlternativeType3corresponds to the "multipart/alternative" subtype, meaning the body parts are alternative representations of the same information, as described in RFC 2046.

See alsosetContentType().

Member Function Documentation

QHttpMultiPart::QHttpMultiPart(QObject * parent = 0)

Constructs aQHttpMultiPart with content typeMixedType and setsparent as the parent object.

See alsoQHttpMultiPart::ContentType.

QHttpMultiPart::QHttpMultiPart(ContentType contentType,QObject * parent = 0)

Constructs aQHttpMultiPart with content typecontentType and sets parent as the parent object.

See alsoQHttpMultiPart::ContentType.

QHttpMultiPart::~QHttpMultiPart()

Destroys the multipart.

void QHttpMultiPart::append(constQHttpPart & httpPart)

AppendshttpPart to this multipart.

QByteArray QHttpMultiPart::boundary() const

returns the boundary.

See alsosetBoundary().

void QHttpMultiPart::setBoundary(constQByteArray & boundary)

Sets the boundary toboundary.

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.

See alsoboundary().

void QHttpMultiPart::setContentType(ContentType contentType)

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

See alsoQHttpMultiPart::ContentType andQNetworkAccessManager::post().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp