使用 libcurl 下载 Gzip 内容而不压缩

Downloading Gzip'ed content with libcurl without deflating

我想以 gzip 格式检索网页,但我不想压缩它,而是想将 gzip 字节写入文件流。这可能吗?如果我没有为 gzip 发送正确的 accepts header,我会得到正常的 html 内容,但是如果我确实发送了 accepts gzip header,那么 libcurl 会自动取消它。我是否能够在没有解压缩开销的情况下检索原始压缩字节?

如果您将 Accept-Encoding: gzip 作为自定义 header 传递给 CURLOPT_HTTPHEADER, libcurl won't decompress it automatically. It will only automatically decompress gzip if you set CURLOPT_ACCEPT_ENCODING