c - 使用 WININET API 处理 GZIP 压缩

标签 c winapi com ole wininet

我的服务器向我发送一个使用 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/

相关文章:

c - 解方程与函数指针的困难

c - 如果我给指针一个普通值会怎样

windows - C++/W32 - 录制声音、Direct Show 或 WaveInOpen?

c# - SetWindowPos 插入之后,而不是之前?

c++ - 使用 IDispatch::Invoke 的 OLE 交互参数构造

c++ - 如何获取 libutils.so

c - 字符串数组打印出垃圾值

excel - VBA:在类模块中模拟 AddressOf 运算符的解决方法

com - “参数”: ambiguous conversions from 'Foo *const ' to 'IUnknown *'

c++ - 如何在 Borland C++ 中使用 .NET 类