本文来自于Thinkai’s Blog,thinkai也是我在ahk上面的引路人,对thinkai感兴趣的朋友请关注他的博客。
thinkai的博客简洁、有趣,即便是转载过来我也尽量保持作者原有的风格,主要是方便大家查阅。
thinkai的博客简洁、有趣,即便是转载过来我也尽量保持作者原有的风格,主要是方便大家查阅。
GZURLDownloadToVar(url, Encoding = "",Method="GET",postData="",headers:=""){ hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1") Try { hObject.SetTimeouts(30000,30000,300000,300000) hObject.Open(Method,url,True) if IsObject(headers) { for k,v in headers { if v hObject.SetRequestHeader(k, v) } } hObject.Send(postData) hObject.WaitForResponse(-1) } catch e return -1 } GZIP_DecompressResponseBody(hObject, retHtml, Encoding) return retHtml } GZIP_DecompressBuffer(ByRef var, nSz ){ static hModule, _ If !hModule { hModule := DllCall("LoadLibrary", "Str", "gzip.dll", "Ptr") _ := { base: {__Delete: "GZIP_DecompressBuffer"} } } If !_ Return DllCall("FreeLibrary", "Ptr", hModule) vSz := NumGet( var,nsz-4 ), VarSetCapacity( out,vsz,0 ) DllCall( "GZIPInitDecompression" ) DllCall( "GZIPCreateDecompression", UIntP,CTX, UInt,1 ) If ( DllCall( "GZIPDecompress", UInt,CTX, UInt,&var, UInt,nsz, UInt,&Out, UInt,vsz , UIntP,input_used, UIntP,output_used ) = 0 && ( Ok := ( output_used = vsz ) ) ) VarSetCapacity( var,64 ), VarSetCapacity( var,0 ), VarSetCapacity( var,vsz,32 ) , DllCall( "RtlMoveMemory", UInt,&var, UInt,&out, UInt,vsz ) DllCall( "GZIPDestroyDecompression", UInt,CTX ), DllCall( "GZIPDeInitDecompression" ) Return Ok ? vsz : 0 } GZIP_DecompressResponseBody(ByRef oWinHttp, ByRef retHtml, encoding:="UTF-8") { If ( oWinHttp.GetResponseHeader("Content-Encoding") != "gzip" ) Return True, retHtml := oWinHttp.ResponseText body := oWinHttp.ResponseBody VarSetCapacity(data, size := body.MaxIndex() + 1) DllCall("oleaut32SafeArrayAccessData", "ptr", ComObjValue(body), "ptr*", pdata) DllCall("RtlMoveMemory", "ptr", &data, "ptr", pdata, "ptr", size) DllCall("oleaut32SafeArrayUnaccessData", "ptr", ComObjValue(body)) size := GZIP_DecompressBuffer(data, size) retHtml := StrGet(&data, size, encoding) }
大佬,麻烦问下这个代码需要导入文件吗?post请求的数据应该怎么添加
这是一个下载文件的案例,你可以根据这个写法写自己的函数,通过com实现的