문제

Is it possible to read undecoded data from QNetworkReply?

Response is encoded using gzip (Content-Encoding: gzip HTTP header), but when i call readAll() method it returns decoded data. I need raw gzipped data, as it was sent to me. Any ideas?

도움이 되었습니까?

해결책

You have to set yourself the header for your QNetworkRequest:

 networkRequest.setRawHeader("Accept-Encoding", "gzip");

Then Qt doesn't decode for you in the reply.

We can see in the source of qhttpnetworkconnection.cpp for QHttpNetworkConnectionPrivate::prepareRequest:

    // If the request had a accept-encoding set, we better not mess
    // with it. If it was not set, we announce that we understand gzip
    // and remember this fact in request.d->autoDecompress so that
    // we can later decompress the HTTP reply if it has such an
    // encoding.
    value = request.headerField("accept-encoding");
    if (value.isEmpty()) {
#ifndef QT_NO_COMPRESS
        request.setHeaderField("Accept-Encoding", "gzip");
        request.d->autoDecompress = true;
#else
        // if zlib is not available set this to false always
        request.d->autoDecompress = false;
#endif
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top