I'm new here and already have a few months I'm working with autoit, I would ask for help. What I need: Transparency of access when I need to upload, send an image to a url and capture a token response that validates that the image was received. Requirement: url expects base64 content The user will not see the image uploading, so it receives the token. As to thinking:
Rode with an HTTP POST method to simulate an access that url, I establish in a guy to see if he returns with status HTTP is 200 If so, he takes the token and returns pro user If not, it returns error message
Down here has two functions for Post and Base64, it's not working
I cut the url from Post methods
#include "WinHttp.au3"
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$Error = ObjEvent("AutoIt.Error", "_Error")
_POST()
Func _POST()
; Method
$oHTTP.Open("POST", "/", False)
;Add Accept
$oHTTP.SetRequestHeader("Accept:","text/html", "application/xhtml+xml", "*/*")
; Add Referer
$oHTTP.SetRequestHeader("Referer:", "")
;Add Accept-Language
$oHTTP.SetRequestHeader("Accept-Language:","pt-BR")
;Add User-Agent
$oHTTP.SetRequestHeader("User-Agent:", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)")
;Add Content Type
$oHTTP.SetRequestHeader("Content-Type:","multipart/form-data")
;Add Host
$oHTTP.SetRequestHeader("Host:", "")
;Add Content-Length
$oHTTP.SetRequestHeader("Content-Length:" , "")
;Add Connection
$oHTTP.SetRequestHeader("Connection:","Keep-Alive")
;Add Cache-Control
$oHTTP.SetRequestHeader("Cache-Control:","no-cache" & @CRLF)
;Send
$oHTTP.Send("DATATOSEND")
;Body
$oReceived = $oHTTP.ResponseText
;Object status
$oStatusCode = $oHTTP.Status
;Verifiy Status
If $oStatusCode = 200 then
SelectAll_and_Copy( 250, 300 )
;SaveText( 250, 300, $output_file2 )
MsgBox(4096, "Response code", $oStatusCode)
EndIf
If $oStatusCode Not 200 Then
Return 0
ConsoleWriteError ("Couldn't receive HTTP 200")
EndIf
; Salva Resposta do Body, independente do codigo de Resposta
;O valor de 2 sobrescreve o arquivo se ele já existe
$file = FileOpen("Received.html", 2)
FileWrite($file, $oReceived)
FileClose($file)
EndFunc
Func _Base64Encode($buf)
Local $c = 0, $i = 1, $j = 0, $l = BinaryLen($buf), $m = Mod($l, 3)
Local $dest = ""
While $i <= $l - $m
$c = BitOR(BitShift(BinaryMid($buf, $i, 1), -16), BitShift(BinaryMid($buf, $i + 1, 1), -8), BinaryMid($buf, $i + 2, 1))
$dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 16515072), 18)])
$dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 258048), 12)])
$dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 4032), 6)])
$dest &= Chr($_BASE64_TABLE[BitAND($c, 63)])
$i += 3
$j += 4
WEnd
If 1 = $m Then
$dest &= Chr($_BASE64_TABLE[BitShift(BitAND(BinaryMid($buf, $i, 1), 252), 2)])
$dest &= Chr($_BASE64_TABLE[BitShift(BitAND(BinaryMid($buf, $i, 1), 3), -4)])
$dest &= Chr($_BASE64_TABLE[64])
$dest &= Chr($_BASE64_TABLE[64])
ElseIf 2 = $m Then
$c = BitOR(BitShift(BinaryMid($buf, $i, 1), -8), BinaryMid($buf, $i + 1, 1))
$dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 64512), 10)])
$dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 1008), 4)])
$dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 15), -2)])
$dest &= Chr($_BASE64_TABLE[64])
EndIf
Return $dest
EndFunc