AGS package for the library Curl.au3, created by Ward. It provides an own implementation of libcurl in AutoIt
npm install @autoit-gui-skeleton/ags-wrapper-curlAGS-wrapper-curl
================
> AutoIt Gui Skeleton package for wrapping the library Curl.au3 created by Ward. See this package on npmjs.com
autoit
#Include "../Curl.au3"
; How to get html or header data?
; 1. Set $CURLOPT_WRITEFUNCTION and $CURLOPT_HEADERFUNCTION to Curl_DataWriteCallback()
; 2. Set $CURLOPT_WRITEDATA or $CURLOPT_HEADERDATA to any number as identify
; 3. Use Curl_Data_Get() to read the returned data in binary format
; 4. Use Curl_Data_Cleanup() to remove the data
Local $Curl = Curl_Easy_Init()
If Not $Curl Then Return
Local $Html = $Curl ; any number as identify
Local $Header = $Curl + 1 ; any number as identify
; Curl configuration
Curl_Easy_Setopt($Curl, $CURLOPT_URL, "https://www.google.com")
Curl_Easy_Setopt($Curl, $CURLOPT_USERAGENT, "AutoIt/Curl")
Curl_Easy_Setopt($Curl, $CURLOPT_FOLLOWLOCATION, 1)
Curl_Easy_Setopt($Curl, $CURLOPT_ACCEPT_ENCODING, "gzip") ; or set "" use all built-in supported encodings
Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_DataWriteCallback())
Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $Html)
Curl_Easy_Setopt($Curl, $CURLOPT_HEADERFUNCTION, Curl_DataWriteCallback())
Curl_Easy_Setopt($Curl, $CURLOPT_HEADERDATA, $Header)
Curl_Easy_Setopt($Curl, $CURLOPT_COOKIE, "tool=curl; script=autoit; fun=yes;")
Curl_Easy_Setopt($Curl, $CURLOPT_TIMEOUT, 30)
Curl_Easy_Setopt($Curl, $CURLOPT_SSL_VERIFYPEER, 0)
; Perform curl request
Local $Code = Curl_Easy_Perform($Curl)
If $Code = $CURLE_OK Then
ConsoleWrite("Content Type: " & Curl_Easy_GetInfo($Curl, $CURLINFO_CONTENT_TYPE) & @LF)
ConsoleWrite("Download Size: " & Curl_Easy_GetInfo($Curl, $CURLINFO_SIZE_DOWNLOAD) & @LF)
MsgBox(0, 'Header', BinaryToString(Curl_Data_Get($Header)))
MsgBox(0, 'Html', BinaryToString(Curl_Data_Get($Html)))
Else
ConsoleWrite(Curl_Easy_StrError($Code) & @LF)
EndIf
Curl_Easy_Cleanup($Curl)
Curl_Data_Cleanup($Header)
Curl_Data_Cleanup($Html)
`
$3
By default, libcurl respects the proxy environment variables named http_proxy, ftp_proxy, sftp_proxy etc. If set, libcurl will use the specified proxy for that URL scheme. So for a "FTP://" URL, the ftp_proxy is considered. all_proxy is used if no protocol specific proxy was set. If no_proxy is set, it is the exact equivalent of setting the CURLOPT_NOPROXY option. But if you want to ovveride envrionnement variables, it's possible with the $CURLOPT_PROXY and CURLOPT_NOPROXY options.
To set a proxy, use :
`
Curl_Easy_Setopt($Curl, $CURLOPT_PROXY, 'https://myProxy.com:8080');
`
To disable default proxy configuration, use :
`autoit
Curl_Easy_Setopt($Curl, $CURLOPT_PROXY, '');
`
$3
The multi interface provides in libcurl offers several abilities that the easy interface (default mode use in libcurl) does not. They are mainly:
1. Enable a "pull" interface. The application that uses libcurl decides where and when to ask libcurl to get/send data.
2. Enable multiple simultaneous transfers in the same thread without making it complicated for the application.
3. Enable the application to wait for action on its own file descriptors and curl's file descriptors simultaneously.
4. Enable event-based handling and scaling transfers up to and beyond thousands of parallel connections.
> See more : https://curl.se/libcurl/c/libcurl-multi.html
`autoit
Local $Curl = Curl_Easy_Init()
If Not $Curl Then Return
Curl_Easy_Setopt($Curl, $CURLOPT_URL, "http://www.google.com")
Curl_Easy_Setopt($Curl, $CURLOPT_USERAGENT, "AutoIt/Curl")
Curl_Easy_Setopt($Curl, $CURLOPT_FOLLOWLOCATION, 1)
Curl_Easy_Setopt($Curl, $CURLOPT_ACCEPT_ENCODING, "")
Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_DataWriteCallback())
Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $Curl)
Curl_Easy_Setopt($Curl, $CURLOPT_HEADERFUNCTION, Curl_DataWriteCallback())
Curl_Easy_Setopt($Curl, $CURLOPT_HEADERDATA, $Curl + 1)
Local $Multi = Curl_Multi_Init()
If Not $Multi Then Return
Curl_Multi_Add_Handle($Multi, $Curl)
Local $Running, $MsgsInQueue
Do
Curl_Multi_Perform($Multi, $Running)
Local $CURLMsg = Curl_Multi_Info_Read($Multi, $MsgsInQueue)
If DllStructGetData($CURLMsg, "msg") = $CURLMSG_DONE Then
Local $Curl = DllStructGetData($CURLMsg, "easy_handle")
Local $Code = DllStructGetData($CURLMsg, "data")
If $Code = $CURLE_OK Then
ConsoleWrite("Content Type: " & Curl_Easy_GetInfo($Curl, $CURLINFO_CONTENT_TYPE) & @LF)
ConsoleWrite("Download Size: " & Curl_Easy_GetInfo($Curl, $CURLINFO_SIZE_DOWNLOAD) & @LF)
MsgBox(0, 'Header', BinaryToString(Curl_Data_Get($Curl + 1)))
MsgBox(0, 'Html', BinaryToString(Curl_Data_Get($Curl)))
Else
ConsoleWrite(Curl_Easy_StrError($Code) & @LF)
EndIf
Curl_Multi_Remove_Handle($Multi, $Curl)
Curl_Easy_Cleanup($Curl)
Curl_Data_Cleanup($Curl)
Curl_Data_Cleanup($Curl + 1)
EndIf
ConsoleWrite("non-GUI-blocking" & @LF)
Sleep(10)
Until $Running = 0
Curl_Multi_Cleanup($Multi)
ConsoleWrite(@LF)
`
$3
See the Examples script for detail usage.
How to install AGS-wrapper-curl ?
We assume that you have already install Node.js and Yarn, for example by taking a Chocolatey. AGS framework use Yarn for manage dependencies.
To add this package into your AutoIt project, just type in the root folder of your AGS project where the package.json is stored. You can also modify the dependencies property of this json file and use the yarn install command. It is easier to use the add command :
`
λ yarn add @autoit-gui-skeleton/ags-wrapper-curl --modules-folder vendor
`
The property dependencies of the package.json file is updated consequently, and all package dependencies, as well as daughter dependencies of parent dependencies, are installed in the ./vendor/@autoit-gui-skeleton/ directory. Note that with an AGS project, it is not necessary to explicitly write this option --modules-folder vendor on the command line, thanks to the .yarnrc file stored at the root of the project. Yarn automatically use .yarnrc file to add an additional configuration of options.
`
#./.yarnrc
--modules-folder vendor
`
Finally to use this library in your AutoIt program, you need to include this library in the main program. There is no need for additional configuration to use it.
`autoit
#include './vendor/@autoit-gui-skeleton/ags-wrapper-curl/Curl.au3'
``