繁体   English   中英

从QNetworkReply读取未解码的数据

[英]Read undecoded data from QNetworkReply

是否可以从QNetworkReply读取未解码的数据?

响应使用gzip( Content-Encoding:gzip HTTP头) 编码 ,但是当我调用readAll()方法时,它返回解码数据。 我需要原始的gzip压缩数据,因为它是发送给我的。 有任何想法吗?

您必须为自己设置QNetworkRequest的标头:

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

然后Qt在回复中没有为你解码。

我们可以在qhttpnetworkconnection.cpp的源代码中看到 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM