Advertisement
Baoulettes

HttpQueryInfo Function v2

Oct 15th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HttpQueryInfo Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;Source: post by olfen "DllCall: HttpQueryInfo - Get HTTP headers"
  3. ;                       http://www.autohotkey.com/forum/post-64567.html#64567
  4. ;
  5. ; For flag info, see: http://msdn.microsoft.com/en-us/library/aa385351(VS.85).aspx
  6.  
  7. HttpQueryInfo(URL, QueryInfoFlag=21, Proxy="", ProxyBypass="") {
  8. hModule := DllCall("LoadLibrary", "str", dll := "wininet.dll")
  9.  
  10. ; Adapt for build by 0x150||ISO
  11. ver := ( A_IsUnicode && !RegExMatch( A_AhkVersion, "\d+\.\d+\.4" ) ? "W" : "A" )
  12. InternetOpen := dll "\InternetOpen" ver
  13. HttpQueryInfo := dll "\HttpQueryInfo" ver
  14. InternetOpenUrl := dll "\InternetOpenUrl" ver
  15.  
  16. If (Proxy != "")
  17. AccessType=3
  18. Else
  19. AccessType=1
  20.  
  21. io_hInternet := DllCall( InternetOpen
  22. , "str", ""
  23. , "uint", AccessType
  24. , "str", Proxy
  25. , "str", ProxyBypass
  26. , "uint", 0) ;dwFlags
  27. If (ErrorLevel != 0 or io_hInternet = 0) {
  28. DllCall("FreeLibrary", "uint", hModule)
  29. return, -1
  30. }
  31.  
  32. iou_hInternet := DllCall( InternetOpenUrl
  33. , "uint", io_hInternet
  34. , "str", url
  35. , "str", ""
  36. , "uint", 0
  37. , "uint", 0x80000000
  38. , "uint", 0)
  39. If (ErrorLevel != 0 or iou_hInternet = 0) {
  40. DllCall("FreeLibrary", "uint", hModule)
  41. return, -1
  42. }
  43.  
  44. VarSetCapacity(buffer, 1024, 0)
  45. VarSetCapacity(buffer_len, 4, 0)
  46.  
  47. Loop, 5
  48. {
  49.   hqi := DllCall( HttpQueryInfo
  50.   , "uint", iou_hInternet
  51.   , "uint", QueryInfoFlag
  52.   , "uint", &buffer
  53.   , "uint", &buffer_len
  54.   , "uint", 0)
  55.   If (hqi = 1) {
  56.     hqi=success
  57.     break
  58.   }
  59. }
  60.  
  61. IfNotEqual, hqi, success, SetEnv, res, timeout
  62.  
  63. If (hqi = "success") {
  64. p := &buffer
  65. Loop
  66. {
  67.   l := DllCall("lstrlen", "UInt", p)
  68.   VarSetCapacity(tmp_var, l+1, 0)
  69.   DllCall("lstrcpy", "Str", tmp_var, "UInt", p)
  70.   p += l + 1
  71.   res := res . tmp_var
  72.   If (*p = 0)
  73.   Break
  74. }
  75. }
  76.  
  77. DllCall("wininet\InternetCloseHandle",  "uint", iou_hInternet)
  78. DllCall("wininet\InternetCloseHandle",  "uint", io_hInternet)
  79. DllCall("FreeLibrary", "uint", hModule)
  80.  
  81. return, res
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement