C++ 从QNetworkReply读取未编码的数据

C++ 从QNetworkReply读取未编码的数据,c++,qt,http,gzip,qnetworkaccessmanager,C++,Qt,Http,Gzip,Qnetworkaccessmanager,是否可以从QNetworkReply中读取未编码的数据 响应是使用gzip(内容编码:gzip HTTP头)编码的,但当我调用readAll()方法时,它返回解码数据。我需要原始的Gzip数据,因为它是发送给我的。有什么想法吗?您必须为您的QNetworkRequest设置标题: networkRequest.setRawHeader("Accept-Encoding", "gzip"); // If the request had a accept-encoding set, we

是否可以从QNetworkReply中读取未编码的数据


响应是使用gzip(内容编码:gzip HTTP头)编码的,但当我调用readAll()方法时,它返回解码数据。我需要原始的Gzip数据,因为它是发送给我的。有什么想法吗?

您必须为您的
QNetworkRequest设置标题

 networkRequest.setRawHeader("Accept-Encoding", "gzip");
    // 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
    }
那么Qt不会在回复中为您解码

我们可以在for
QHttpNetworkConnectionPrivate::prepareRequest的源代码中看到:

 networkRequest.setRawHeader("Accept-Encoding", "gzip");
    // 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
    }
有关