找回密码
 加入
搜索
查看: 2862|回复: 0

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

[复制链接]
发表于 2015-5-20 16:45:09 | 显示全部楼层 |阅读模式
本帖最后由 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[0]);
$charset = 0
If StringRegExp($aRequest[0], "(?im)^Content-Type:\h.*?charset\h*=\h*utf-?8") Then $charset = 4
If StringRegExp($aRequest[0], "(?im)^Content-Encoding:\h+gzip") Then
    $sResponse = BinaryToString(_ZLIB_GZUncompress($aRequest[1]), $charset)
Else
    $sResponse = BinaryToString($aRequest[1], $charset)
EndIf
MsgBox(0,"",$sResponse)

_WinHttpCloseHandle($aRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-25 21:03 , Processed in 0.088616 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表