QHttpPart Class
QHttpPart 클래스는 HTTP 멀티파트 MIME 메시지 내에서 사용할 본문 부분을 보관합니다. 더 보기...
헤더: | #include <QHttpPart> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Network) target_link_libraries(mytarget PRIVATE Qt6::Network) |
qmake: | QT += network |
- 상속된 멤버를 포함한 모든 멤버 목록
- QHttpPart는 네트워크 프로그래밍 API와 암시적으로 공유되는 클래스의 일부입니다.
공용 함수
QHttpPart() | |
QHttpPart(const QHttpPart &other) | |
~QHttpPart() | |
void | setBody(const QByteArray &body) |
void | setBodyDevice(QIODevice *device) |
void | setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value) |
void | setRawHeader(const QByteArray &headerName, const QByteArray &headerValue) |
void | swap(QHttpPart &other) |
bool | operator!=(const QHttpPart &other) const |
QHttpPart & | operator=(const QHttpPart &other) |
bool | operator==(const QHttpPart &other) const |
관련 비회원
(since 6.8) QDebug | operator<<(QDebug debug, const QHttpPart &part) |
상세 설명
QHttpPart 클래스는 HTTP 멀티파트 MIME 메시지( QHttpMultiPart 클래스로 표현됨) 내에서 사용할 본문 부분을 보유합니다. QHttpPart는 헤더 블록과 데이터 블록으로 구성되며, 두 개의 연속된 새 줄로 서로 구분됩니다. 한 파트의 예는 다음과 같습니다:
Content-Type: text/plain Content-Disposition: form-data; name="text" here goes the body
헤더를 설정하려면 QNetworkRequest::setHeader() 및 QNetworkRequest::setRawHeader()와 똑같이 동작하는 setHeader() 및 setRawHeader()를 사용합니다.
작은 데이터 조각을 읽으려면 setBody(), 이미지와 같은 큰 데이터 블록을 읽으려면 setBodyDevice()을 사용합니다. 후자의 방법은 데이터를 내부적으로 복사하지 않고 디바이스에서 직접 읽음으로써 메모리를 절약합니다. 즉, 본문 부분이 포함된 멀티파트 메시지가 QNetworkAccessManager::post()를 통해 네트워크에서 전송될 때 디바이스가 열려 있고 읽을 수 있어야 합니다.
작은 본문으로 QHttpPart를 구성하려면 다음 스니펫을 고려하세요(위 예제에 표시된 데이터를 생성합니다):
QHttpPart textPart; textPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain")); textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\"")); textPart.setBody("here goes the body");
장치(예: 파일)에서 읽는 QHttpPart를 구성하려면 다음을 적용할 수 있습니다:
QHttpPart imagePart; imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\"")); imagePart.setRawHeader("Content-ID", "my@content.id"); // add any headers you like via setRawHeader() QFile *file = new QFile("image.jpg"); file->open(QIODevice::ReadOnly); imagePart.setBodyDevice(file);
QHttpPart는 설정 시 디바이스의 소유권을 가져가지 않으므로 더 이상 필요하지 않을 때 디바이스를 삭제하는 것은 개발자의 책임이라는 점에 유의하세요. QHttpMultiPart 에 대한 문서에 설명된 대로 멀티파트 메시지를 디바이스의 부모 객체로 설정하는 것이 좋습니다.
QHttpMultiPart 와 QNetworkAccessManager도 참조하세요 .
멤버 함수 문서
QHttpPart::QHttpPart()
빈 QHttpPart 객체를 생성합니다.
QHttpPart::QHttpPart(const QHttpPart &other)
other 의 복사본을 만듭니다.
[noexcept]
QHttpPart::~QHttpPart()
이것을 파괴합니다 QHttpPart.
void QHttpPart::setBody(const QByteArray &body)
이 MIME 파트의 본문을 body 로 설정합니다. setBodyDevice()를 통해 설정하지 않는 한 이 메서드로 설정한 본문이 사용됩니다. 많은 양의 데이터(예: 이미지)의 경우 내부적으로 데이터를 복사하지 않는 setBodyDevice()를 사용합니다.
setBodyDevice()도 참조하세요 .
void QHttpPart::setBodyDevice(QIODevice *device)
디바이스가 device 에서 콘텐츠를 읽도록 설정합니다. 대량의 데이터의 경우 이 메서드를 사용하면 콘텐츠가 복사되지 않고 장치에서 직접 읽히므로 setBody()보다 이 메서드를 선호해야 합니다. device 은 열려 있고 읽을 수 있어야 합니다. QHttpPart 은 device 의 소유권을 갖지 않습니다. 즉, 필요한 경우 장치를 닫고 파괴해야 합니다. device 이 순차적(예: 파일이 아닌 소켓)인 경우 QNetworkAccessManager::post()은 device 이 finished()를 보낸 후에 호출해야 합니다. 장치를 설정 해제하고 setBody()를 통해 설정된 데이터를 사용하려면 "setBodyDevice(0)"를 사용합니다.
setBody() 및 QNetworkAccessManager::post()도 참조하세요 .
void QHttpPart::setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
알려진 헤더 header 의 값을 value 으로 설정하여 이전에 설정된 모든 헤더를 재정의합니다.
QNetworkRequest::KnownHeaders, setRawHeader() 및 QNetworkRequest::setHeader()도 참조하세요 .
void QHttpPart::setRawHeader(const QByteArray &headerName, const QByteArray &headerValue)
headerName 헤더를 headerValue 값으로 설정합니다. headerName 이 알려진 헤더( QNetworkRequest::KnownHeaders 참조)에 해당하는 경우 원시 형식이 파싱되고 그에 해당하는 "쿠킹된" 헤더도 설정됩니다.
참고: 동일한 헤더를 두 번 설정하면 이전 설정이 재정의됩니다. 같은 이름의 여러 HTTP 헤더를 동작시키려면 두 값을 쉼표(",")로 구분하여 연결하고 하나의 원시 헤더를 설정해야 합니다.
QNetworkRequest::KnownHeaders, setHeader() 및 QNetworkRequest::setRawHeader()도 참조하세요 .
[noexcept]
void QHttpPart::swap(QHttpPart &other)
이 HTTP 부분을 other 로 바꿉니다. 이 작업은 매우 빠르며 실패하지 않습니다.
bool QHttpPart::operator!=(const QHttpPart &other) const
이 객체가 other 과 같지 않으면 true
을 반환합니다.
operator==()도 참조하세요 .
QHttpPart &QHttpPart::operator=(const QHttpPart &other)
other 의 복사본을 만듭니다.
bool QHttpPart::operator==(const QHttpPart &other) const
이 객체가 other 과 동일한 경우(즉, 헤더와 본문이 동일한 경우) true
을 반환합니다.
operator!=()도 참조하세요 .
© 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.