Leaderboard
Popular Content
Showing content with the highest reputation on 08/16/2022 in Posts
-
Curl UDF - libcurl with x64 support
Stormgrade reacted to Beege for a topic
Here is a rewrite of Wards Curl UDF with the binary portion removed so that it can support external (updated) library's and add support for x64. I added quite a few new header constants and also have included the curl-ca-bundle certificate. I modified the first two "easy" examples to demonstrate using the ca-bundle to verify the SSL peer. I also added a new example showing how to download the certificate chain. The 7.82.0 version dlls are included but they can be replaced with updated versions as they come out in the future. You can find future releases here : https://curl.se/windows/ Let me know if you have any issues. Cheers! 🙂 Curlx64.7z1 point -
Your initial example, when sent to the POSTMAN Echo API, sends the form data correctly. Are you sure you are posting the correct script and error message? If so, then the problem is probably the format of the POST data. It would help if you provided more information about the API. The site doesn't have API examples? You could also try URL encoding your POST data before sending it. The second $sPostData in my example has the string URL encoded. Both ways produce the same result when sent to the POSTMAN Echo API. However, your API server may want the URL encoded string when special characters exist. If so, there are several URL encoding & decoding functions posted to the forum. Just do a search for URLEncode. Example: #include <Constants.au3> #include <MyIncludes\json\json.au3> http_post_example() Func http_post_example() Local $oComErr = Null ;~ Local $sPostData = 'username=myrealusername&password=]=oN9>fh2!O' Local $sPostData = 'username=myrealusername&password=%5D=oN9%3Efh2!O' ;URL Encoded ;Register COM Error Handler $oComErr = ObjEvent("AutoIt.Error", com_error_handler) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", _ "Unable to register COM error handler - @error = " & @error) ;Send POST request using WINHTTP COM object With ObjCreate("winhttp.winhttprequest.5.1") ;Open POST request, set request header(s), and send the request .Open("POST", "https://postman-echo.com/post") If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", _ StringFormat("(0x%X) %s", $oComErr.RetCode, $oComErr.WinDescription)) .SetRequestHeader("Content-Type" , "application/x-www-form-urlencoded") .SetRequestHeader("Accept" , "application/json") .SetRequestHeader("Cache-Control", "no-cache") .Send($sPostData) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", _ StringFormat("(0x%X) %s", $oComErr.RetCode, $oComErr.Description)) ConsoleWrite(StringFormat("HTTP Status: %s (%s)", .Status, .StatusText) & @CRLF) ;If http status code not 200, exit with message If .Status <> 200 Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", _ StringFormat("HTTP Status Code = %s %s", .Status, .StatusText)) ;Display formatted JSON response ConsoleWrite(@CRLF & "HTTP Response:" & @CRLF) ConsoleWrite(Json_Encode(Json_Decode(.ResponseText), $JSON_PRETTY_PRINT + $JSON_UNESCAPED_SLASHES) & @CRLF) EndWith EndFunc Func com_error_handler($oError) With $oError ConsoleWrite(@ScriptName & " (" & .scriptline & ") : ==> COM Error intercepted !" & @CRLF) ConsoleWrite(@TAB & "Error Number........... " & "0x" & Hex(.number) & @CRLF) ConsoleWrite(@TAB & "Error WinDescription... " & StringStripWS(.windescription, $STR_STRIPTRAILING) & @CRLF) ConsoleWrite(@TAB & "Error Description...... " & StringStripWS(.description , $STR_STRIPTRAILING) & @CRLF) ConsoleWrite(@TAB & "Error ScriptLine....... " & .scriptline & @CRLF) ConsoleWrite(@TAB & "Error RetCode.......... " & "0x" & Hex(.retcode) & @CRLF) EndWith Return ; Return so @error can be trapped by the calling function EndFunc Output: HTTP Status: 200 (OK) HTTP Response: { "args": {}, "data": "", "files": {}, "form": { "username": "myrealusername", "password": "]=oN9>fh2!O" }, "headers": { "x-forwarded-proto": "https", "x-forwarded-port": "443", "host": "postman-echo.com", "x-amzn-trace-id": "Root=1-62fc3310-05b42b003c0bbd127b09c301", "content-length": "44", "cache-control": "no-cache", "content-type": "application/x-www-form-urlencoded; Charset=UTF-8", "accept": "application/json", "user-agent": "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)" }, "json": { "username": "myrealusername", "password": "]=oN9>fh2!O" }, "url": "https://postman-echo.com/post" }1 point
-
Take a look at https://www.autoitscript.com/autoit3/docs/functions/ControlSetText.htm Edit : You can add the € sign behind the numeric string ( ... & " €"). This will be ignored by the Number function (but don't put it before the value !). Which position is suitable for this operation, however, I can not judge, because I only see your code snippet.1 point
-
Here is little optimized version: 1) In StringReplace use CaseSense=1 -> faster 2) StringReplace+StringStripWS do only if neccessary (just before Beep) -> less CPU load in main loop $sTextOld = '' While True If WinActive("[Title:Caja]") Then ;Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21") ;Get data from "TOTAL Textbox" If $sText <> $sTextOld Then ;Beep if "TOTAL Textbox" value changes If Number(StringReplace(StringStripWS($sText, 8), ',', '.',1)) <> 0 Then Beep(660, 300) ;Beep sound (not when 0 / 0,00) $sTextOld = $sText EndIf EndIf Sleep(0) WEnd1 point
-
To use DllCall() correctly, be aware of the following: The AutoIt DllCall() function can only be used to execute functions in dll-files implemented in unmanaged languages such as C, C++ and Pascal. The DllCall() function cannot be used to execute functions in .NET assembly dll-files implemented in managed languages such as C#, F# or VB.NET. Note that this isn't an AutoIt limitation or a limitation in the DllCall() function. It's a very general limitation when trying to mix any unmanaged programming language with managed code. AutoIt is an unmanaged programming language. Fortunately, there are methods to integrate unmanaged and managed code. This also applies to AutoIt and C# code. With an AutoIt background, the DotNetAll.au3 UDF as implemented in Using C# and VB.NET Code is by far the easiest way to execute C# (or VB.NET) code directly within an AutoIt script. With this technique you have eg. no need for a C# (or VB.NET) IDE, but can handle all code in SciTE. See bottom of this post for a complete list of the benefits of the technique. But this method works best if the C# (or VB.NET) code only depends on internal .NET assembly dll-files or relatively simple external .NET assembly dll-files. In your case it seems to be a slightly more advanced external .NET assembly dll-file. To be sure to get the code working in AutoIt, use the technique briefly demonstrated in this post. This method requires an IDE to compile the C# code into a .NET assembly dll-file and it requires the dll-file to be registered with RegAsm.exe. Why is more C# code needed when a .NET assembly dll file already exists and contains the actual UploadZipFile() method? In your case with the UploadZipFile() method, it is necessary to add a bit more C# code to use the method in AutoIt. The problem is that UploadZipFile() is a static method, and a static method cannot be executed in AutoIt. In the C# code, you must include the .NET assembly dll file and you must write a small wrapper method that works in AutoIt. The wrapper method must be a simple public method as shown in the example in the link and the method must of course call the static UploadZipFile() method. Depending on your experience with AutoIt objects and C# code, getting the code to work isn't necessarily a completely trivial task.1 point
-
First post on the forums Thanks so much for this! Made my day a lot easier! I'm using the HttpGet function in a GUI and if the page is not available my GUI starts freezing up so I added in $oHTTP.SetTimeouts to help with error handling. Func HttpGet($sURL, $sData = "") Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.Open("GET", $sURL & "?" & $sData, False) $oHTTP.SetTimeouts(50, 50, 50, 50) If (@error) Then Return SetError(1, 0, 0) $oHTTP.Send() If (@error) Then Return SetError(2, 0, 0) If ($oHTTP.Status <> 200) Then Return SetError(3, 0, 0) Return SetError(0, 0, $oHTTP.ResponseText) EndFunc ;==>HttpGet The values are for ResolveTimeout, ConnectTimeout, SendTimeout, ReceiveTimeout. I've set to 50ms because I'm working with a LAN connection and my requests are tiny.1 point