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( "GZIP\InitDecompression" ) DllCall( "GZIP\CreateDecompression", UIntP,CTX, UInt,1 ) If ( DllCall( "GZIP\Decompress", 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( "GZIP\DestroyDecompression", UInt,CTX ), DllCall( "GZIP\DeInitDecompression" ) 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("oleaut32\SafeArrayAccessData", "ptr", ComObjValue(body), "ptr*", pdata) DllCall("RtlMoveMemory", "ptr", &data, "ptr", pdata, "ptr", size) DllCall("oleaut32\SafeArrayUnaccessData", "ptr", ComObjValue(body)) size := GZIP_DecompressBuffer(data, size) retHtml := StrGet(&data, size, encoding) }
60 queries in 1.819 seconds |