gpt4 book ai didi

c++ - 从 QNetworkReply 读取未解码的数据

转载 作者:太空狗 更新时间:2023-10-29 23:17:17 24 4
gpt4 key购买 nike

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

响应是使用 gzip(Content-Encoding: gzip HTTP header )编码的,但是当我调用 readAll() 方法时,它会返回解码后的数据。我需要发送给我的原始 gzip 数据。有什么想法吗?

最佳答案

您必须为自己的QNetworkRequest 设置 header :

 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
}

关于c++ - 从 QNetworkReply 读取未解码的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18816279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com