QFormDataPartBuilder Class

The QFormDataPartBuilder class is a convenience class to simplify the construction of QHttpPart 對象。 更多...

頭: #include <QFormDataPartBuilder>
CMake: find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
qmake: QT += network
Since: Qt 6.8

公共函數

QFormDataPartBuilder (const QFormDataPartBuilder & other )
QFormDataPartBuilder (QFormDataPartBuilder && other )
~QFormDataPartBuilder ()
QFormDataPartBuilder setBody (QByteArrayView data , QAnyStringView fileName = {}, QAnyStringView mimeType = {})
QFormDataPartBuilder setBodyDevice (QIODevice * body , QAnyStringView fileName = {}, QAnyStringView mimeType = {})
QFormDataPartBuilder setHeaders (const QHttpHeaders & headers )
QFormDataPartBuilder & operator= (QFormDataPartBuilder && other )
QFormDataPartBuilder & operator= (const QFormDataPartBuilder & other )

詳細描述

The QFormDataPartBuilder class can be used to build a QHttpPart object with the content disposition header set to be form-data by default. Then the generated object can be used as part of a multipart message (which is represented by the QHttpMultiPart class).

另請參閱 QHttpPart , QHttpMultiPart ,和 QFormDataBuilder .

成員函數文檔編製

[default] QFormDataPartBuilder:: QFormDataPartBuilder (const QFormDataPartBuilder & other )

構造副本為 other . The object is valid for as long as the associated QFormDataBuilder has not been destroyed.

The data of the copy is shared (shallow copy): modifying one part will also change the other.

QFormDataPartBuilder foo()
{
    QFormDataBuilder builder;
    auto qfdpb1 = builder.part("First"_L1);
    auto qfdpb2 = qfdpb1; // this creates a shallow copy
    qfdpb2.setBodyDevice(&image, "cutecat.jpg"); // qfdpb1 is also modified
    return qfdbp2;  // invalid, builder is destroyed at the end of the scope
}
					

[noexcept default] QFormDataPartBuilder:: QFormDataPartBuilder ( QFormDataPartBuilder && other )

Move-constructs a QFormDataPartBuilder instance, making it point at the same object that other 所指嚮的。

[noexcept default] QFormDataPartBuilder:: ~QFormDataPartBuilder ()

銷毀 QFormDataPartBuilder 對象。

QFormDataPartBuilder QFormDataPartBuilder:: setBody ( QByteArrayView data , QAnyStringView fileName = {}, QAnyStringView mimeType = {})

設置 data as the body of this MIME part and, if given, fileName as the file name parameter in the content disposition header.

mimeType is not given (is empty), then QFormDataPartBuilder tries to auto-detect the mime-type of data 使用 QMimeDatabase .

A subsequent call to setBodyDevice () discards the body and the device will be used instead.

For a large amount of data (e.g. an image), setBodyDevice () is preferred, which will not copy the data internally.

另請參閱 setBodyDevice ().

QFormDataPartBuilder QFormDataPartBuilder:: setBodyDevice ( QIODevice * body , QAnyStringView fileName = {}, QAnyStringView mimeType = {})

設置 body as the body device of this part and fileName as the file name parameter in the content disposition header.

mimeType is not given (is empty), then QFormDataPartBuilder tries to auto-detect the mime-type of body 使用 QMimeDatabase .

A subsequent call to setBody () discards the body device and the data set by setBody () will be used instead.

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.

body must be open and readable. QFormDataPartBuilder 未擁有所有權對於 body , i.e. the device must be closed and destroyed if necessary.

注意: body is sequential (e.g. sockets, but not files), QNetworkAccessManager::post () should be called after body has emitted finished().

另請參閱 setBody () 和 QHttpPart::setBodyDevice ().

QFormDataPartBuilder QFormDataPartBuilder:: setHeaders (const QHttpHeaders & headers )

Sets the headers specified in headers .

注意: The "content-type" and "content-disposition" headers, if any are specified in headers , will be overwritten by the class.

[default] QFormDataPartBuilder &QFormDataPartBuilder:: operator= ( QFormDataPartBuilder && other )

移動賦值 other 到此 QFormDataPartBuilder 實例。

[default] QFormDataPartBuilder &QFormDataPartBuilder:: operator= (const QFormDataPartBuilder & other )

賦值 other to QFormDataPartBuilder and returns a reference to this QFormDataPartBuilder . The object is valid for as long as the associated QFormDataBuilder has not been destroyed.

The data of the copy is shared (shallow copy): modifying one part will also change the other.

QFormDataPartBuilder foo()
{
    QFormDataBuilder builder;
    auto qfdpb1 = builder.part("First"_L1);
    auto qfdpb2 = qfdpb1; // this creates a shallow copy
    qfdpb2.setBodyDevice(&image, "cutecat.jpg"); // qfdpb1 is also modified
    return qfdbp2;  // invalid, builder is destroyed at the end of the scope
}