我的服务器向我发送一个使用 GZIP 压缩进行压缩的 JSON 数据流。
当我在普通 IE 浏览器上请求此数据时,我会获取数据,当我提到要打开的应用程序时,浏览器会自动解压缩该数据流并向我显示我的 JSON 数据。
我的 C 应用程序正在使用 COM/OLE 嵌入 IE 浏览器实例,并且我正在使用 WININET 进行 GET/POST 操作,因此我在这里获取压缩的数据。
由于其 IE 浏览器功能可以在默认 IE 浏览器的情况下自动解压缩 GZIP 数据 如何在我的 C 应用程序中通过 WININET 自动解密数据?
最佳答案
启动 Vista,INTERNET_OPTION_HTTP_DECODING
标志启用 WinInet 中的 gzip 解码:
INTERNET_OPTION_HTTP_DECODING :
Enables WinINet to perform decoding for the gzip and deflate encoding schemes. For more information, see Content Encoding.
When decoding fails, the application has two options: it can remove the Accept-Encoding header and resend the request, or it can set the INTERNET_OPTION_HTTP_DECODING option on the request to false and then resend the request. If the decoding option is set to false, the application must check the Content-Encoding header and perform any decoding at the application level.
在早期版本的 Windows 中,您必须自行解压(使用 http://zlib.net/ 也相当容易)
关于c - 使用 WININET API 处理 GZIP 压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12024363/