Juno_okyo

HTTP Function

Sep 15th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.90 KB | None | 0 0
  1. Global $cookies[1][2]
  2.  
  3. $res = getHTTP("https://www.fshare.vn/login?fs_csrf=" & $getCSRF[0] & '&LoginForm%5Bemail%5D=' & URLEncode(BinaryToString($user)) & '&LoginForm%5Bpassword%5D=' & URLEncode(BinaryToString($pword)) & '&LoginForm%5BrememberMe%5D=0&yt0=%C4%90%C4%83ng+nh%E1%BA%ADp', mkCookies(), "https://www.fshare.vn/login", 0, 1, 0)
  4.  
  5. Func getHTTP($lnk, $cookie = '', $refer = '', $ignorecookies = 0, $post = 0, $redir = 0)
  6.         Local $method = "GET"
  7.         Local $weblink = StringSplit($lnk, '?')
  8. ;~      _ArrayDisplay($weblink)
  9.         If $post = 1 Then
  10.                 $method = "POST"
  11.                 Local $linklink = $weblink[1]
  12.                 Local $poststring = $weblink[2]
  13.         Else
  14.                 Local $linklink = $lnk
  15.         EndIf
  16.         $OHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
  17.         If $redir = 0 Then
  18.                 $OHTTP.Option(6) = False
  19.         EndIf
  20.         $OHTTP.Open($method, $linklink, False)
  21.         $OHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0")
  22.         If StringLen($refer) > 1 Then
  23.                 $OHTTP.SetRequestHeader("Referer", $refer)
  24.         EndIf
  25.         If StringLen($cookie) > 1 Then
  26.                 $OHTTP.SetRequestHeader("Cookie", $cookie)
  27.         EndIf
  28.         If $post = 1 Then
  29.                 $OHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
  30.                 $OHTTP.SetRequestHeader("Content-Length", StringLen($poststring))
  31.                 $OHTTP.Send($poststring)
  32.         Else
  33.                 $OHTTP.Send()
  34.         EndIf
  35.         $OHTTP.WaitForResponse
  36.         Local $HeaderResponses = $OHTTP.GetAllResponseHeaders()
  37.         If $ignorecookies = 0 Then
  38.                 ; Handle Cookies
  39.                 Local $array = StringRegExp($HeaderResponses, 'Set-Cookie: (.+)\r\n', 3)
  40.                 ;$cookies = ''
  41.                 For $i = 0 To UBound($array) - 1
  42.                         ; Add all cookies to a single string, and then clean it up.
  43.                         Local $cook = $array[$i] & ';'
  44.                         ; Removing parts we do not use..
  45.                         $cook = StringRegExpReplace($cook, "( path| domain| expires)=[^;]+", "")
  46.                         $cook = StringRegExpReplace($cook, " HttpOnly", "")
  47.                         $cook = StringRegExpReplace($cook, "[;]{2,}", ";")
  48.                         Local $cook1 = StringSplit($cook, ";")
  49.                         For $k = 1 To $cook1[0]
  50.                                 If StringInStr($cook1[$k], "=") Then
  51.                                         Local $cook2 = StringSplit(StringReplace($cook1[$k], " ", ""), "=")
  52.                                         If $cookies[0][0] == "" Then
  53.                                                 $cookies[0][0] = $cook2[1]
  54.                                                 $cookies[0][1] = $cook2[2]
  55.                                         Else
  56.                                                 Local $inserted = 0
  57.                                                 For $j = 0 To UBound($cookies) - 1
  58.                                                         If $cook2[1] == $cookies[$j][0] Then
  59.                                                                 $cookies[$j][1] = $cook2[2]
  60.                                                                 $inserted = 1
  61.                                                         ElseIf ($j == (UBound($cookies) - 1)) And ($inserted == 0) Then
  62.                                                                 ReDim $cookies[UBound($cookies) + 1][2]
  63.                                                                 $cookies[UBound($cookies) - 1][0] = $cook2[1]
  64.                                                                 $cookies[UBound($cookies) - 1][1] = $cook2[2]
  65.                                                         EndIf
  66.                                                 Next
  67.                                         EndIf
  68.                                 EndIf
  69.                         Next
  70.                 Next
  71.         EndIf
  72.         Dim $ret[4]
  73.         If StringInStr($HeaderResponses, "Location:") <> 0 Then
  74.                 $ret["0"] = $OHTTP.GetResponseHeader("Location")
  75.                 $ret["1"] = 1
  76.         Else
  77.                 $ret["0"] = ""
  78.                 $ret["1"] = 0
  79.         EndIf
  80.         $ret["2"] = $OHTTP.Responsetext
  81.         $ret["3"] = $OHTTP.GetAllResponseHeaders()
  82.         Return $ret
  83. ;~      return  [0]: location
  84. ;~                      [1]: 1/0
  85. ;~                      [2]: ResponseText
  86. ;~                      [3]: All Header
  87. EndFunc   ;==>getHTTP
  88.  
  89. Func mkCookies()
  90.         Local $rt = ""
  91.         Local $j
  92.         For $j = 0 To UBound($cookies) - 1
  93.                 $rt = $rt & $cookies[$j][0] & "=" & $cookies[$j][1]
  94.                 If $j <> (UBound($cookies) - 1) Then
  95.                         $rt = $rt & "; "
  96.                 EndIf
  97.         Next
  98.         Return $rt
  99. EndFunc   ;==>mkCookies
Add Comment
Please, Sign In to add comment