Advertisement
Guest User

HTTP function by Coockie

a guest
Aug 14th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. http (adress, type := "application/x-www-form-urlencoded", method := "GET", error_log := false, package := "") {
  2.     if (!RegExMatch(adress, "^http[s]?:\/\/.*\..*$")) {
  3.         return error_log ? "Invalid URL adress (#1)" : false
  4.     } else if (!DllCall("Wininet.dll\InternetGetConnectedState", "Str", 0x20, "Int", 0)) {
  5.         return error_log ? "Not internet connection (#2)" : false
  6.     }
  7.     try {
  8.         http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  9.         http.Open(method, adress, false)
  10.         http.SetRequestHeader("Referer", adress)
  11.         http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36 u01-05")
  12.         http.SetRequestHeader("Content-Type", type)
  13.         http.SetRequestHeader("Pragma","no-cache")
  14.         http.Send(package)
  15.         http.WaitForResponse()
  16.         if (!StrLen(http.ResponseText)) {
  17.             return error_log ? "Empty response (#3)" : false
  18.         } else {
  19.             if (http.Status !== 200) {
  20.                 return error_log ? http.Status "(" http.StatusText ") (#4)" : false
  21.             } else {
  22.                 return http.ResponseText
  23.             }
  24.         }
  25.     } catch e {
  26.         return error_log ? e.message "(#5)" : false    
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement