Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HttpQueryInfo Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;Source: post by olfen "DllCall: HttpQueryInfo - Get HTTP headers"
- ; http://www.autohotkey.com/forum/post-64567.html#64567
- ;
- ; For flag info, see: http://msdn.microsoft.com/en-us/library/aa385351(VS.85).aspx
- HttpQueryInfo(URL, QueryInfoFlag=21, Proxy="", ProxyBypass="") {
- hModule := DllCall("LoadLibrary", "str", dll := "wininet.dll")
- ; Adapt for build by 0x150||ISO
- ver := ( A_IsUnicode && !RegExMatch( A_AhkVersion, "\d+\.\d+\.4" ) ? "W" : "A" )
- InternetOpen := dll "\InternetOpen" ver
- HttpQueryInfo := dll "\HttpQueryInfo" ver
- InternetOpenUrl := dll "\InternetOpenUrl" ver
- If (Proxy != "")
- AccessType=3
- Else
- AccessType=1
- io_hInternet := DllCall( InternetOpen
- , "str", ""
- , "uint", AccessType
- , "str", Proxy
- , "str", ProxyBypass
- , "uint", 0) ;dwFlags
- If (ErrorLevel != 0 or io_hInternet = 0) {
- DllCall("FreeLibrary", "uint", hModule)
- return, -1
- }
- iou_hInternet := DllCall( InternetOpenUrl
- , "uint", io_hInternet
- , "str", url
- , "str", ""
- , "uint", 0
- , "uint", 0x80000000
- , "uint", 0)
- If (ErrorLevel != 0 or iou_hInternet = 0) {
- DllCall("FreeLibrary", "uint", hModule)
- return, -1
- }
- VarSetCapacity(buffer, 1024, 0)
- VarSetCapacity(buffer_len, 4, 0)
- Loop, 5
- {
- hqi := DllCall( HttpQueryInfo
- , "uint", iou_hInternet
- , "uint", QueryInfoFlag
- , "uint", &buffer
- , "uint", &buffer_len
- , "uint", 0)
- If (hqi = 1) {
- hqi=success
- break
- }
- }
- IfNotEqual, hqi, success, SetEnv, res, timeout
- If (hqi = "success") {
- p := &buffer
- Loop
- {
- l := DllCall("lstrlen", "UInt", p)
- VarSetCapacity(tmp_var, l+1, 0)
- DllCall("lstrcpy", "Str", tmp_var, "UInt", p)
- p += l + 1
- res := res . tmp_var
- If (*p = 0)
- Break
- }
- }
- DllCall("wininet\InternetCloseHandle", "uint", iou_hInternet)
- DllCall("wininet\InternetCloseHandle", "uint", io_hInternet)
- DllCall("FreeLibrary", "uint", hModule)
- return, res
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement