Search the Community
Showing results for tags 'winhttp.au3'.
-
I try to download some file with winhttp.au3 I use code from here: My code looks like: #include <FileConstants.au3> #include "WinHttp.au3" #AutoIt3Wrapper_Run_AU3Check=N _Example() Func _Example() ; Initialize and get session handle Local $hOpen = _WinHttpOpen() ; Get connection handle Local $hConnect = _WinHttpConnect($hOpen, "https://MY_URL") Local $CurrentOption = _WinHttpQueryOption($hConnect, $WINHTTP_OPTION_SECURITY_FLAGS) Local $Options = BitOR($CurrentOption, _ $SECURITY_FLAG_IGNORE_UNKNOWN_CA, _ $SECURITY_FLAG_IGNORE_CERT_CN_INVALID, _ $SECURITY_FLAG_IGNORE_CERT_DATE_INVALID) _WinHttpSetOption($hConnect, $WINHTTP_OPTION_SECURITY_FLAGS, $Options) If @error Then ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & _ " : _WinHttpSetOption" & @CRLF) ; Specify the reguest Local $hRequest = _WinHttpOpenRequest($hConnect, Default, "MY_FILE") ; Send request _WinHttpSendRequest($hRequest) ; Wait for the response _WinHttpReceiveResponse($hRequest) ProgressOn("Downloading", "In Progress...") Progress(_WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_LENGTH)) Local $sData ; Check if there is data available... If _WinHttpQueryDataAvailable($hRequest) Then While 1 $sChunk = _WinHttpReadData_Ex($hRequest, Default, Default, Default, Progress) If @error Then ExitLoop $sData &= $sChunk Sleep(20) WEnd Else MsgBox(48, "Error", "Site is experiencing problems (or you).") EndIf Sleep(1000) ProgressOff() ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Local $hFile = FileOpen(@ScriptDir & "\MY_FILE", $FO_OVERWRITE + $FO_CREATEPATH + $FO_BINARY) FileWrite($hFile, $sData) FileClose($hFile) EndFunc ;==>_Example Func Progress($iSizeAll, $iSizeChunk = 0) Local Static $iMax, $iCurrentSize If $iSizeAll Then $iMax = $iSizeAll $iCurrentSize += $iSizeChunk Local $iPercent = Round($iCurrentSize / $iMax * 100, 0) ProgressSet($iPercent, $iPercent & " %") EndFunc ;==>Progress Func _WinHttpReadData_Ex($hRequest, $iMode = Default, $iNumberOfBytesToRead = Default, $pBuffer = Default, $vFunc = Default) __WinHttpDefault($iMode, 0) __WinHttpDefault($iNumberOfBytesToRead, 8192) __WinHttpDefault($vFunc, 0) Local $tBuffer, $vOutOnError = "" If $iMode = 2 Then $vOutOnError = Binary($vOutOnError) Switch $iMode Case 1, 2 If $pBuffer And $pBuffer <> Default Then $tBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]", $pBuffer) Else $tBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]") EndIf Case Else $iMode = 0 If $pBuffer And $pBuffer <> Default Then $tBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]", $pBuffer) Else $tBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]") EndIf EndSwitch Local $sReadType = "dword*" If BitAND(_WinHttpQueryOption(_WinHttpQueryOption(_WinHttpQueryOption($hRequest, $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_CONTEXT_VALUE), $WINHTTP_FLAG_ASYNC) Then $sReadType = "ptr" Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpReadData", _ "handle", $hRequest, _ "struct*", $tBuffer, _ "dword", $iNumberOfBytesToRead, _ $sReadType, 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, "") If Not $aCall[4] Then Return SetError(-1, 0, $vOutOnError) If IsFunc($vFunc) Then $vFunc(0, $aCall[4]) If $aCall[4] < $iNumberOfBytesToRead Then Switch $iMode Case 0 Return SetExtended($aCall[4], StringLeft(DllStructGetData($tBuffer, 1), $aCall[4])) Case 1 Return SetExtended($aCall[4], BinaryToString(BinaryMid(DllStructGetData($tBuffer, 1), 1, $aCall[4]), 4)) Case 2 Return SetExtended($aCall[4], BinaryMid(DllStructGetData($tBuffer, 1), 1, $aCall[4])) EndSwitch Else Switch $iMode Case 0, 2 Return SetExtended($aCall[4], DllStructGetData($tBuffer, 1)) Case 1 Return SetExtended($aCall[4], BinaryToString(DllStructGetData($tBuffer, 1), 4)) EndSwitch EndIf EndFunc ;==>_WinHttpReadData_Ex As a result I get file with this contents: As so far I found this: So I even with added: Local $CurrentOption = _WinHttpQueryOption($hConnect, $WINHTTP_OPTION_SECURITY_FLAGS) Local $Options = BitOR($CurrentOption, _ $SECURITY_FLAG_IGNORE_UNKNOWN_CA, _ $SECURITY_FLAG_IGNORE_CERT_CN_INVALID, _ $SECURITY_FLAG_IGNORE_CERT_DATE_INVALID) _WinHttpSetOption($hConnect, $WINHTTP_OPTION_SECURITY_FLAGS, $Options) If @error Then ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & _ " : _WinHttpSetOption" & @CRLF) I still get the same errors. Anyone know a way how to fix this problem? Regards, mLipok
-
Hi, sometimes when I run my script in GUI (SciTe Editor) or as an executable file, the chrome driver launches but the chrome browser does not but when I re-run the script again - chrome driver launches and so does the browser. Here is the error that I'm getting: __WD_Post: StatusCode=0; ResponseText=WinHTTP request timed out before Webdriver... __WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver _WD_CreateSession: WinHTTP request timed out before Webdriver _WD_CreateSession ==> Webdriver Exception: HTTP status = 0 Just wondering if there's a way to re-launch both the driver and browser without having to rerun the script/executable.
-
Hi again, this is my last option to retrieve file from server via web. ; Initialize and get session handle $hOpen = _WinHttpOpen() _writeLog("return $hOpen:" &$hOpen) ; Get connection handle $hConnect = _WinHttpConnect($hOpen, $url, $INTERNET_DEFAULT_HTTPS_PORT) _writeLog("return $hConnect:" &$hConnect) ; Fill the login form: $check_login = _WinHttpSimpleFormFill($hConnect, _ $hOpen, _ "id1", _ "name:LoginForm[userName]", $userID, _ "name:LoginForm[password]", $password,_ "[IGNORE_CERT_ERRORS]") If @error Then _writeLog("login failed : " & @error) _writeLog("check login UIS" &$check_login) ; Close connection handle _WinHttpCloseHandle($hConnect) ; Open new connection handle $hConnect = _WinHttpConnect($hOpen, $url, $INTERNET_DEFAULT_HTTPS_PORT) $s_data = _WinHttpSimpleSSLRequest($hConnect,Default,$Download_url,Default,Default,Default,Default,2) ; BINARY ;$s_data = _WinHttpSimpleSSLRequest($hConnect, Default, $Download_url) _writeLog("return $s_data " &$s_data) ; Close connection handle _WinHttpCloseHandle($hConnect) ; Close session handle _WinHttpCloseHandle($hOpen) ; Open the file for writing (append to the end of a file) and store the handle to a variable. Local $hFileOpen = FileOpen($sFilePath, 18) If $hFileOpen = -1 Then _writeLog("An error occurred whilst writing the temporary file.") EndIf ;Write the data to the file FileWrite($hFileOpen ,$s_data) FileClose($hFileOpen) However it paused at _WinHttpSimpleSSLRequest before this received error: 1 $url = "https://192.168.10.167/ui/login" $Download_url https://192.168.10.167/ui/backup/files?3-1.ILinkListener-files-1-download Any idea?
- 1 reply
-
- winhttp.au3
- _winhttpsimpleformfill
-
(and 1 more)
Tagged with:
-
I'm trying to download a file from our server at work which requires a login. InetGet is not working so I was looking round for another method. I came across winhttp.au3 but it seems like this is not shipped with the Autoit ZIP I have. (v3.3.14) Anyone have any ideas of where to get it, because I can't find it. I also searched the forum, thinking it was trancexx who made it. (maybe I'm wrong here....) Or is it obsolete and is there another / better way? Any suggestions?
-
Good Morning AutoIT Geniuses! Now, it could be that I've been away for a while - but I can get source from just about any website except adobe using InetGetSource. I have no idea why... error: 13 https://helpx.adobe.com/security.html https://helpx.adobe.com/security.html?promoid=HRYCM Thanks! #include <Inet.au3> HttpSetUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko") Local $sOpenAdobe_URLSecurityUpdates = 'https://helpx.adobe.com/security.html' Local $OpenSSL01 = _INetGetSource($sOpenAdobe_URLSecurityUpdates) WinHttp.au3 is returning results - I just don't get it... Thanks! #include "WinHttp.au3" Opt("MustDeclareVars", 1) ; Initialize and get session handle Global $hOpen = _WinHttpOpen() ; Get connection handle Global $hConnect = _WinHttpConnect($hOpen, "helpx.adobe.com") ; Make a request Global $hRequest = _WinHttpSimpleSendRequest($hConnect, Default, "/security.html?promoid=HRYCM") If $hRequest Then ; Simple-read... ConsoleWrite(_WinHttpSimpleReadData($hRequest) & @CRLF) MsgBox(64, "Okey do!", "Returned source is print to concole. Check it.") Else MsgBox(48, "Error", "Error ocurred for _WinHttpSimpleSendRequest, Error number is " & @error) EndIf ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen)
- 7 replies
-
- _inetgetsource
- winhttp.au3
-
(and 1 more)
Tagged with:
-
Hello, It is the second time I am running to this problem again. First time I used simple form fill function from winhttp.au3. And I added a sleep between logins to make it work but this solution sucks. So I am wondering again, is there an other solution to perform a log in on website other than simple form fill? I just want to check credentials so I need to perform log in and then check for the username in the results. Here is an example with simple form fill #include "WinHttp.au3" Global $sRead, $hOpen, $hConnect Global $sUsername, $sPassword, $sName Global $sUrl = "https://www.facebook.com/" Global $sUserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)" $hOpen = _WinHttpOpen($sUserAgent) $hConnect = _WinHttpConnect($hOpen, $sUrl) $sRead = _WinHttpSimpleFormFill($hConnect, _ Default, _ "login_form", _ "name:email", $sUsername, _ "name:pass", $sPassword) If @error Then MsgBox(0, "Error", "Error: " & @error) ElseIf StringInStr($sRead, $sName) = True Then MsgBox(0, "", $sName & "'s credentials are correct.") Else MsgBox(0, "", "Wrong credentials, please try again.") EndIf _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen)
-
Hello, I am trying to make an auto log in script that will log in on our server with all the accounts of the people working on our domain read from the database(arround 20 accounts). The reason for this is everyone to recive update e-mail. We recive update e-mail with the latest updates everytime time we log in so that is the reason that i am creating this. Here is a small reproducer: #include "WinHttp.au3" OnAutoItExitRegister("_sExit") Global $sRead, $hOpen, $hConnect Global Const $sUsername[3] = ["name1", "name2", "name3"] Global Const $sPassword[3] = ["pass1", "pass2", "pass3"] Global Const $sUrl = "https://www.myServer.com/" Global Const $sUserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)" Local $a Local $b $hOpen = _WinHttpOpen($sUserAgent) $hConnect = _WinHttpConnect($hOpen, $sUrl) For $i = 0 To UBound($sUsername)-1 $a = $sUsername[$i] $b = $sPassword[$i] $sRead = _WinHttpSimpleFormFill($hConnect, _ Default, _ "login_1", _ "name:name", $a, _ "name:pass", $b) If @error Then ConsoleWrite(@error & @LF) Else If StringInStr($sRead, $a) Then ConsoleWrite($a & " succesfully logged in." & @LF) EndIf Next Func _sExit() _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) EndFunc If i put the $hOpen and $hConnect within the For/Next loop it will work but it will take more than 1 min to log in on our server with all the accounts. If not it won't work for all the accounts. If i use $hOpen and $hConnect only once then the server will fire error after 4-5 log ins and the winhttpsimpleformfill function will return that there are no forms, @error 1. Any other way to perform a log in without filling the form with data and submitting it? Cheers.
-
Hello, I am trying to make an auto log in script that will log in on our server with all the accounts read from the database(arround 20 accounts). The reason for this is everyone to recive update e-mail. We recive update e-mail everytime time we log in so that is the reason that i am creating this. Here is a small reproducer: #include "WinHttp.au3" OnAutoItExitRegister("_sExit") Global $sRead, $hOpen, $hConnect Global Const $sUsername[3] = ["name1", "name2", "name3"] Global Const $sPassword[3] = ["pass1", "pass2", "pass3"] Global Const $sUrl = "https://www.myServer.com/" Global Const $sUserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)" Local $a Local $b $hOpen = _WinHttpOpen($sUserAgent) $hConnect = _WinHttpConnect($hOpen, $sUrl) For $i = 0 To UBound($sUsername)-1 $a = $sUsername[$i] For $j = 0 To UBound($sPassword)-1 $b = $sPassword[$i] ExitLoop Next $sRead = _WinHttpSimpleFormFill($hConnect, _ Default, _ "login_1", _ "name:name", $a, _ "name:pass", $b) If @error Then ConsoleWrite(@error & @LF) Else If StringInStr($sRead, $a) Then ConsoleWrite($a & " succesfully logged in." & @LF) EndIf Next Func _sExit() _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) EndFunc This work but not very good. The script will log in succesfully with the first 5-10 accounts but then it will return _WinHttpSimpleFormFill will return an error because of the fast log in on the server. Is there an other way to do this without filling the form with data and submiting it? Like a simple request that will load the http with the credentials without doing the classic form fill? Cheers