簡體   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