user11 发表于 2015-5-20 16:45:09

[已解决]WinHttp_GetRespond网页返回数据流为gzip格式如何解压?

本帖最后由 user11 于 2015-5-20 17:06 编辑

写了个小程序,使用了WinHttp_GetRespond,但是返回数据格式是gizp压缩过的,Content-Encoding: gzip


怎么显示出明码呢,原来用xmlhttp是可以自动解压的,


winhttp如何让数据自动显示出来,谢谢~!

去官网down了个好东西,nb啊,作者Kudo这样写的,本来zlib是要dll的,然后作者写了个UDF,因为他穷开心,因为他会写

To use zLib in AutoIt, the easiest way is download the DLL, and then just use it by DllCall, or warp it by my

But now I convert zLib to machine code version UDF, because "just for fun", or because I can.

https://www.autoitscript.com/forum/topic/128962-zlib-deflateinflategzip-udf/

#include<WinHttp.au3>
#include<zlib.au3>

$sURL = "http://abc.com/xyz.html"

$hOpen = _WinHttpOpen("Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.0.3; .NET CLR 2.0.50727; ffco7) Gecko/2008092417 Firefox/3.0.3")

$hConnect = _WinHttpConnect($hOpen, $sURL)

;~ $hRequest = _WinHttpSimpleRequest($hConnect)
$aRequest = _WinHttpSimpleRequest($hConnect, Default,Default,Default,Default,'Accept-Encoding: gzip',1,2)

ConsoleWrite($aRequest);
$charset = 0
If StringRegExp($aRequest, "(?im)^Content-Type:\h.*?charset\h*=\h*utf-?8") Then $charset = 4
If StringRegExp($aRequest, "(?im)^Content-Encoding:\h+gzip") Then
    $sResponse = BinaryToString(_ZLIB_GZUncompress($aRequest), $charset)
Else
    $sResponse = BinaryToString($aRequest, $charset)
EndIf
MsgBox(0,"",$sResponse)

_WinHttpCloseHandle($aRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
页: [1]
查看完整版本: [已解决]WinHttp_GetRespond网页返回数据流为gzip格式如何解压?