Qt 4.8
|
The QHttpPart class holds a body part to be used inside a HTTP multipart MIME message. More...
#include <qhttpmultipart.h>
Public Functions | |
bool | operator!= (const QHttpPart &other) const |
Returns true if this object is not the same as other. More... | |
QHttpPart & | operator= (const QHttpPart &other) |
Creates a copy of other. More... | |
bool | operator== (const QHttpPart &other) const |
Returns true if this object is the same as other (i.e., if they have the same headers and body). More... | |
QHttpPart () | |
Constructs an empty QHttpPart object. More... | |
QHttpPart (const QHttpPart &other) | |
Creates a copy of other. More... | |
void | setBody (const QByteArray &body) |
Sets the body of this MIME part to body. More... | |
void | setBodyDevice (QIODevice *device) |
Sets the device to read the content from to device. More... | |
void | setHeader (QNetworkRequest::KnownHeaders header, const QVariant &value) |
Sets the value of the known header header to be value, overriding any previously set headers. More... | |
void | setRawHeader (const QByteArray &headerName, const QByteArray &headerValue) |
Sets the header headerName to be of value headerValue. More... | |
~QHttpPart () | |
Destroys this QHttpPart. More... | |
Properties | |
QSharedDataPointer< QHttpPartPrivate > | d |
Friends | |
class | QHttpMultiPartIODevice |
The QHttpPart class holds a body part to be used inside a HTTP multipart MIME message.
The QHttpPart class holds a body part to be used inside a HTTP multipart MIME message (which is represented by the QHttpMultiPart class). A QHttpPart consists of a header block and a data block, which are separated by each other by two consecutive new lines. An example for one part would be:
For setting headers, use setHeader() and setRawHeader(), which behave exactly like QNetworkRequest::setHeader() and QNetworkRequest::setRawHeader().
For reading small pieces of data, use setBody(); for larger data blocks like e.g. images, use setBodyDevice(). The latter method saves memory by not copying the data internally, but reading directly from the device. This means that the device must be opened and readable at the moment when the multipart message containing the body part is sent on the network via QNetworkAccessManager::post().
To construct a QHttpPart with a small body, consider the following snippet (this produces the data shown in the example above):
To construct a QHttpPart reading from a device (e.g. a file), the following can be applied:
Be aware that QHttpPart does not take ownership of the device when set, so it is the developer's responsibility to destroy it when it is not needed anymore. A good idea might be to set the multipart message as parent object for the device, as documented at the documentation for QHttpMultiPart.
Definition at line 58 of file qhttpmultipart.h.
QHttpPart::QHttpPart | ( | ) |
Constructs an empty QHttpPart object.
Definition at line 102 of file qhttpmultipart.cpp.
QHttpPart::QHttpPart | ( | const QHttpPart & | other | ) |
QHttpPart::~QHttpPart | ( | ) |
|
inline |
Returns true if this object is not the same as other.
Definition at line 66 of file qhttpmultipart.h.
bool QHttpPart::operator== | ( | const QHttpPart & | other | ) | const |
Returns true if this object is the same as other (i.e., if they have the same headers and body).
Definition at line 136 of file qhttpmultipart.cpp.
void QHttpPart::setBody | ( | const QByteArray & | body | ) |
Sets the body of this MIME part to body.
The body set with this method will be used unless the device is set via setBodyDevice(). For a large amount of data (e.g. an image), use setBodyDevice(), which will not copy the data internally.
Definition at line 189 of file qhttpmultipart.cpp.
void QHttpPart::setBodyDevice | ( | QIODevice * | device | ) |
Sets the device to read the content from to device.
For large amounts of data this method should be preferred over setBody(), because the content is not copied when using this method, but read directly from the device. device must be open and readable. QHttpPart does not take ownership of device, i.e. the device must be closed and destroyed if necessary. if device is sequential (e.g. sockets, but not files), QNetworkAccessManager::post() should be called after device has emitted finished(). For unsetting the device and using data set via setBody(), use "setBodyDevice(0)".
Definition at line 209 of file qhttpmultipart.cpp.
void QHttpPart::setHeader | ( | QNetworkRequest::KnownHeaders | header, |
const QVariant & | value | ||
) |
Sets the value of the known header header to be value, overriding any previously set headers.
Definition at line 158 of file qhttpmultipart.cpp.
void QHttpPart::setRawHeader | ( | const QByteArray & | headerName, |
const QByteArray & | headerValue | ||
) |
Sets the header headerName to be of value headerValue.
If headerName corresponds to a known header (see QNetworkRequest::KnownHeaders), the raw format will be parsed and the corresponding "cooked" header will be set as well.
Note: setting the same header twice overrides the previous setting. To accomplish the behaviour of multiple HTTP headers of the same name, you should concatenate the two values, separating them with a comma (",") and set one single raw header.
Definition at line 176 of file qhttpmultipart.cpp.
|
friend |
Definition at line 78 of file qhttpmultipart.h.
|
private |
Definition at line 76 of file qhttpmultipart.h.
Referenced by operator=(), operator==(), QHttpMultiPartIODevice::readData(), setBody(), setBodyDevice(), setHeader(), setRawHeader(), and ~QHttpPart().