QHttpMultiPart Class
QHttpMultiPart 클래스는 HTTP를 통해 전송되는 MIME 멀티파트 메시지와 유사합니다. 더 보기...
헤더: | #include <QHttpMultiPart> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Network) target_link_libraries(mytarget PRIVATE Qt6::Network) |
qmake: | QT += network |
상속합니다: | QObject |
- 상속된 멤버를 포함한 모든 멤버 목록
- QHttpMultiPart는 네트워크 프로그래밍 API의 일부입니다.
공용 타입
enum | ContentType { MixedType, RelatedType, FormDataType, AlternativeType } |
공용 함수
QHttpMultiPart(QObject *parent = nullptr) | |
QHttpMultiPart(QHttpMultiPart::ContentType contentType, QObject *parent = nullptr) | |
virtual | ~QHttpMultiPart() |
void | append(const QHttpPart &httpPart) |
QByteArray | boundary() const |
void | setBoundary(const QByteArray &boundary) |
void | setContentType(QHttpMultiPart::ContentType contentType) |
상세 설명
QHttpMultiPart는 RFC 2046에 설명된 대로 HTTP를 통해 전송되는 MIME 멀티파트 메시지와 유사합니다. 멀티파트 메시지는 고유한 경계로 구분되는 임의의 수의 본문 부분( QHttpPart 참조)으로 구성됩니다. QHttpMultiPart의 경계는 "boundary_.oOo._" 문자열과 임의의 문자로 구성되며, 파트 자체 내부에서 발생하지 않도록 충분한 고유성을 제공합니다. 원하는 경우 setBoundary()를 통해 경계를 설정할 수도 있습니다.
예를 들어 텍스트 부분과 이미지 부분이 포함된 멀티파트 메시지를 구성하는 다음 코드 스니펫을 살펴보세요:
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.
QHttpPart 및 QNetworkAccessManager::post()도 참조하세요 .
멤버 유형 문서
enum QHttpMultiPart::ContentType
RFC 2046 등에 설명된 멀티파트 하위 유형에 대해 알려진 콘텐츠 유형 목록입니다.
상수 | 값 | 설명 |
---|---|---|
QHttpMultiPart::MixedType | 0 | 는 "멀티파트/혼합" 하위 유형에 해당하며, RFC 2046에 설명된 대로 신체 부위가 서로 독립적임을 의미합니다. |
QHttpMultiPart::RelatedType | 1 | 는 "다중 파트/관련" 하위 유형에 해당하며, 이는 RFC 2387에 설명된 대로 신체 부위가 서로 관련되어 있음을 의미합니다. |
QHttpMultiPart::FormDataType | 2 | RFC 2388에 설명된 대로 본문 부분이 폼 요소를 포함하고 있음을 의미하는 "멀티파트/폼-데이터" 하위 유형에 해당합니다. |
QHttpMultiPart::AlternativeType | 3 | 는 "멀티파트/대체" 하위 유형에 해당하며, 이는 본문 부분이 RFC 2046에 설명된 대로 동일한 정보의 대체 표현임을 의미합니다. |
setContentType()도 참조하세요 .
멤버 함수 문서
[explicit]
QHttpMultiPart::QHttpMultiPart(QObject *parent = nullptr)
콘텐츠 유형이 MixedType 인 QHttpMultiPart를 구성하고 parent 을 부모 개체로 설정합니다.
QHttpMultiPart::ContentType 를참조하세요 .
[explicit]
QHttpMultiPart::QHttpMultiPart(QHttpMultiPart::ContentType contentType, QObject *parent = nullptr)
콘텐츠 유형이 contentType 이고 부모를 상위 객체로 설정하는 QHttpMultiPart를 구성합니다.
QHttpMultiPart::ContentType 를참조하세요 .
[virtual noexcept]
QHttpMultiPart::~QHttpMultiPart()
멀티파트를 파괴합니다.
void QHttpMultiPart::append(const QHttpPart &httpPart)
이 멀티파트에 httpPart 을 추가합니다.
QByteArray QHttpMultiPart::boundary() const
는 경계를 반환합니다.
setBoundary()도 참조하세요 .
void QHttpMultiPart::setBoundary(const QByteArray &boundary)
경계를 boundary 로 설정합니다.
일반적으로 경계를 직접 생성할 필요는 없으며, 생성 시 "boundary_.oOo._" 문자열 뒤에 임의의 문자를 붙여 경계를 시작하고 파트 내부에서 발생하지 않도록 충분한 고유성을 제공합니다.
boundary()도 참조하세요 .
void QHttpMultiPart::setContentType(QHttpMultiPart::ContentType contentType)
콘텐츠 유형을 contentType 으로 설정합니다. 콘텐츠 유형은 QNetworkAccessManager::post()을 통해 멀티파트 메시지를 보낼 때 HTTP 헤더 섹션에 사용됩니다. QHttpMultiPart::ContentType 에 포함되지 않은 멀티파트 하위 유형을 사용하려면 QNetworkRequest 에 직접 "Content-Type" 헤더 필드를 추가한 다음 이 요청을 멀티파트 메시지와 함께 사용하여 게시할 수 있습니다.
QHttpMultiPart::ContentType 및 QNetworkAccessManager::post()도 참조하세요 .
© 2025 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 the GNU 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.