Jump to content
Ward

Curl UDF - AutoIt binary code version of libcurl with SSL support

Recommended Posts

trancexx

You have typo in __Curl_lstrlenW - wrong function called.

Excellent! Thanks for sharing.

  • Like 1

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Ward

You found a bug in one second.... excellent!


新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Share this post


Link to post
Share on other sites
wakillon

When i try examples it return 

__MemoryModule_ModuleRecord and __MemoryModule_RuntimeLoader 

undefined function.

Edit : I have replaced #Include "BinaryCall.au3" by #Include <BinaryCall.au3> and it works !

Thanks

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
Ward

The last BinaryCall.au3 UDF can work with MemoryDll.au3. The related function will be called only if MemoryDll.au3 is included. It is checked inside BinaryCall.au3 by following line:

Static $HasMemoryDll = IsFunc(Execute('__MemoryModule_RuntimeLoader'))

For this Curl UDF. Both old and newer version of BinaryCall.au3 are worked.


新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Share this post


Link to post
Share on other sites
argumentum

to have no complain from ScITE, I changed those lines with Execute
 

If $HasMemoryDll Then
                Local $Module = Execute('__MemoryModule_ModuleRecord("get", Null, $DllName)')
                If $Module Then
                    Local $MemoryGetProcAddress = Execute('__MemoryModule_RuntimeLoader("MemoryGetProcAddress")')
                    If $MemoryGetProcAddress Then $Proc = DllCallAddress("ptr:cdecl", $MemoryGetProcAddress, "ptr", $Module, "str", $ProcName)[0]
                    If Not $Proc Then Return SetError(2, _BinaryCall_LastError("MemoryGetProcAddress failed on " & $ProcName), False)
                EndIf
            EndIf

 

Share this post


Link to post
Share on other sites
KotKot77

Can you give more details on how to use this awesome UDF to post a file, please.

I added the following two lines but it doesn't works (I'm sure that the POSTFIELDS part is wrong) :

Curl_Easy_Setopt($Curl, $CURLOPT_POST, 1)

Curl_Easy_Setopt($Curl, $CURLOPT_POSTFIELDS, "file=@C:\Users\KotKot\Desktop\logo.jpg")

Thanks for your help ...

Edited by KotKot77

Share this post


Link to post
Share on other sites
Mateusz

Can someone write example with PUT request with json content?

In linux I can send it via command:

curl -X PUT -H "Content-Type: application/json" -d'{"id":"1751","title":"some title","attr1":"value1","attr2":"value2"}' https://hostname/service --insecure

and it is working, but can't do the same on AutoIT.

Share this post


Link to post
Share on other sites
wakillon

Hi Ward

I'm a bit annoyed with the $CURLOPT_ACCEPT_ENCODING parameter.

Here is an example for get first bytes (for identify file/html instead of using "Content Type" who is not always reliable)

#Include 'Curl.au3'

Global $Curl, $iBufferSize, $Multi, $Running, $MsgsInQueue, $Code, $CURLMsg

$Curl = Curl_Easy_Init()
If Not $Curl Then Exit
$iBufferSize = 32
Curl_Easy_Setopt($Curl, $CURLOPT_URL, 'http://blogs.perl.org/users/kirk_kimmel/2012/08/q-when-not-to-use-regexp-a-html-parsing.html' )
Curl_Easy_Setopt ( $Curl, $CURLOPT_USERAGENT, 'AutoIt/Curl')
Curl_Easy_Setopt ( $Curl, $CURLOPT_FOLLOWLOCATION, 1 )
;~ An empty string creates an Accept-Encoding header containing all supported encodings.
Curl_Easy_Setopt ( $Curl, $CURLOPT_ACCEPT_ENCODING, '' ) ; Possible values : '', 'identity', 'deflate' or 'gzip'
Curl_Easy_Setopt ( $Curl, $CURLOPT_BUFFERSIZE, $iBufferSize )
Curl_Easy_Setopt ( $Curl, $CURLOPT_RANGE, '0-' & $iBufferSize -1 ) ; get the first n bytes. (Content-Range: bytes 0-31/nTotal )
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 )
$Multi = Curl_Multi_Init()
If Not $Multi Then Exit
Curl_Multi_Add_Handle ( $Multi, $Curl )

Do
    Curl_Multi_Perform ( $Multi, $Running )
    $CURLMsg = Curl_Multi_Info_Read ( $Multi, $MsgsInQueue )
    If DllStructGetData ( $CURLMsg, 'msg' ) = $CURLMSG_DONE Then
        $Curl = DllStructGetData ( $CURLMsg, 'easy_handle' )
        $Code = DllStructGetData ( $CURLMsg, 'data' )
        If $Code = $CURLE_OK Then
            ConsoleWrite ( 'Content Type: ' & Curl_Easy_GetInfo ( $Curl, $CURLINFO_CONTENT_TYPE ) & @CRLF )
            ConsoleWrite ( 'Download Size: ' & Curl_Easy_GetInfo ( $Curl, $CURLINFO_SIZE_DOWNLOAD ) & @CRLF )
            ConsoleWrite ( '- Header : ' & BinaryToString ( Curl_Data_Get ( $Curl + 1 ) ) & @Crlf )
            ConsoleWrite ( '+ Html String : ' & BinaryToString ( Curl_Data_Get ( $Curl ) ) & @Crlf )
            ConsoleWrite ( @CRLF )
            ConsoleWrite ( '> Html Binary : ' & Curl_Data_Get ( $Curl ) & @Crlf )
        Else
            ConsoleWrite ( '! Curl_Easy_StrError : ' & Curl_Easy_StrError ( $Code ) & @CRLF )
        EndIf
        Curl_Multi_Remove_Handle ( $Multi, $Curl )
        Curl_Easy_Cleanup ( $Curl )
        Curl_Data_Cleanup ( $Curl )
        Curl_Data_Cleanup ( $Curl + 1 )
    EndIf
    Sleep ( 10 )
Until $Running = 0
Curl_Multi_Cleanup ( $Multi )
Exit

Theoretically an empty string creates an Accept-Encoding header containing all supported encodings.

But in this case or if i use "gzip", script do not return any datas !

If i use "deflate" or "identity" or I do not use at all the "CURLOPT_ACCEPT_ENCODING" option, script return well datas as expected.

Is it a bug ?

Do you have a suggestion about that ?

 

Thanks.

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
wakillon

Well, I suppose that the problem is not from curl, but from the Buffer Size.

With a Buffer Size set to 128 instead of 32, script returns datas.

May be there is a minimal size to set to the buffer, but i do not find any infos on curl.haxx.se ...

 

Edit : May be a clue at line 189 on Curl.h 

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
gcriaco

Any chance to support AutoIt X64?

 

Thanks and best regards

Peppe

Share this post


Link to post
Share on other sites
czyt
On 2015/6/4 at 7:29 PM, Ward said:

I built my own libcurl for AutoIt based on BinaryCall UDF.
libcurl - the multiprotocol file transfer library

The Features:

  • Pure AutoIt script, no DLLs needed.
  • Build with SSL/TLS and zlib support (without libidn, libiconv, libssh2).
  • Full easy-interface and partial multi-interface support.
  • Data can read from or write to autoit variables or files.
  • Smaller code size (compare to most libcurl DLL).

The version information of this build:

  • Curl Version: libcurl/7.42.1
  • SSL Version: mbedTLS/1.3.10
  • Libz Version: 1.2.8
  • Protocols: ftp,ftps,http,https

Here are the helper functions (not include in libcurl library). 

  • Curl_DataWriteCallback()
  • Curl_DataReadCallback()
  • Curl_FileWriteCallback()
  • Curl_FileReadCallback()
  • Curl_Data_Put()
  • Curl_Data_Get()
  • Curl_Data_Cleanup()

See the example script for detail usage.

Hidden Content

 

Curl.zip

支持啦,原来也是来自中国的兄弟啊~~

thx,Brother from China~~


董小姐,你微笑的时候很美,就像安河桥下,清澈的水...

Share this post


Link to post
Share on other sites
Iczer
Edited by Iczer
fail to post

Share this post


Link to post
Share on other sites
Iczer

I'm trying to make this UDF work under x64, but it seems just dll-repace not enough here

Maybe someone can correctly correct :) __Curl_RuntimeLoader() to work under x64

(for some reason it make post blank if i use any tags, so i uploaded my version of Curl UDF)

 

Curl - x64 & x86.au3

Edited by Iczer
fail to post

Share this post


Link to post
Share on other sites
Biatu

Can't seem to get this working...

Func Example_Post_1()
    Local $Curl = Curl_Easy_Init()
    If Not $Curl Then Return
    $bFile=FileRead("ReportData.7z")
    $tFile=DllStructCreate("byte["&BinaryLen($bFile)&"]")
    DllStructSetData($tFile,1,$bFile)
    $pFile=DllStructGetPtr($tFile)
    Local $HttpPost, $LastItem, $vHeader
    $vHeader=Curl_Slist_Append(0,"Content-Length: "&BinaryLen($bFile))
    Curl_Easy_Setopt($Curl, $CURLOPT_URL, "http://infinitycommunicationsgateway.net/Pub/CxbxBugs/test2.php")
    Curl_Easy_Setopt($Curl, $CURLOPT_USERAGENT, "AutoIt/Curl")
    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_VERBOSE,1)
    Curl_Easy_Setopt($Curl, $CURLOPT_POST, 1)
    Curl_Easy_Setopt($Curl, $CURLOPT_READFUNCTION, Curl_DataReadCallback())
    Curl_Easy_Setopt($Curl, $CURLOPT_READDATA, $bFile)
    Curl_Easy_Setopt($Curl, $CURLOPT_INFILESIZE_LARGE,BinaryLen($bFile))
    Curl_Easy_Setopt($Curl, $CURLOPT_FOLLOWLOCATION, 1)

    Local $Code = Curl_Easy_Perform($Curl)
    If $Code <> $CURLE_OK Then Return ConsoleWrite(Curl_Easy_StrError($Code) & @LF)
    Local $Data = BinaryToString(Curl_Data_Get($Curl))
    Local $EffectiveUrl = Curl_Easy_GetInfo($Curl, $CURLINFO_EFFECTIVE_URL)
    Curl_Easy_Cleanup($Curl)
    Curl_Data_Cleanup($Curl)

    ConsoleWrite("Paste link: " & $EffectiveUrl & @LF)
    Local $Match = $Data
    If @Error Then Return
    ConsoleWrite("RAW Paste Data: " & $Match & @LF)
    ConsoleWrite(@LF)
EndFunc

 


What is what? What is what.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • islandspapand
      By islandspapand
      Hi All
      i am currently trying to add a function to my project that can send SMS, i have gone with Twilio for the sms service that use a REST API.
      I have never worked with an API before, and could use some help.
      I can get my function working with using cURL.exe and copy past command from the website with the following code. And thats great unfortunately i am have issue with character like æøå when sending a SMS appears like a box or ?. this does not happen if i do it from the website so it looks like a Unicode issue in curl.exe.
      I have done some searching on the forum and understand that i should be able to implement this curl command with the WinHTTP UDF from @trancexx so i don't need a third part exe and it might fix my charater issue.
      Unfortunately i really don't understand how i am to change curl commands to the WinHTTP and i was hoping some good maybe give me an example i could learn from.
      Thanks in advanced
      i have removed the AuthToken number from the script.
      _SendSMS("00000000","SomeOne","SMS body info") Func _SendSMS($SendTo,$SendFrom,$Msgtxt) $AccountSID = "ACbb765b3180d5938229eff8b8f63ed1bc" $AuthToken = "Auth Token number" $Data = '"https://api.twilio.com/2010-04-01/Accounts/'&$AccountSID&'/Messages.json"'& _ '-X POST \ --data-urlencode "To=+45'&$SendTo&'" \ --data-urlencode "From='&$SendFrom&'" \ --data-urlencode "Body='&$Msgtxt&'" \ -u '&$AccountSID&':'&$AuthToken&'' ShellExecute(@ScriptDir&"\curl.exe","-k "&$Data) ;~ curl 'https://api.twilio.com/2010-04-01/Accounts/ACbb765b3180d5938229eff8b8f63ed1bc/Messages.json' -X POST \ ;~ --data-urlencode 'To=+4500000000' \ ;~ --data-urlencode 'From=Reception' \ ;~ --data-urlencode 'Body=Test Body' \ ;~ -u ACbb765b3180d5938229eff8b8f63ed1bc:[AuthToken] EndFunc  
       
    • jesus40
      By jesus40
      Hello friends, i have a working curl command that show informations about my account on binance.com, but_it dont work with autoit code without curl.exe.
      I want to do it without curl, because the whole process much Slower_ with StdoutRead (I want get the response in variable.)
      My Curl command in Autoit:
      This 2 are works, but_ i would like to do it without curl.exe
      $apikey="XYZ" sCommand = @ScriptDir & '\curl.exe -k -H "X-MBX-APIKEY: ' & $apikey & '" -X GET "https://api.binance.com/api/v3/account?' & $request the same in .bat  file
      curl.exe -k -H "X-MBX-APIKEY: XYZ" -X GET "https://api.binance.com/api/v3/account?timestamp=1514917812000&signature=85bdee77e53cd521e1d5229fbfb459d53799c42b3fa4596d73f1520fad5f965a" (I use curl with -k option which allows curl to make insecure connections, because there is problem with the sites certificate, (cURL error 60))
       
      I tried many variations, this is the latest... I cant get the same response.
      curl $error message (I changed ): {"code":-2015,"msg":"Invalid API-key, IP, or permissions for action."}
      autoit version $error message (Response code:400): Mandatory parameter 'timestamp' was not sent, was empty/null, or malformed.
       
      $request = $query & '&signature=' & $signature $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "https://api.binance.com/api/v3/account", False) $oHTTP.SetRequestHeader("X-MBX-APIKEY", $apikey) $oHTTP.Send($request) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If $oStatusCode <> 200 then MsgBox(4096, "Response code", $oStatusCode) EndIf  
      thanks
    • wakillon
      By wakillon
      HttpHeaderWatcher v1.0.1.3
       

      Some time ago, some members asked how to see the Http Requests.
      There are quite a few external applications but not in AutoIt!
      HttpHeaderWatcher in association with WinPcap, very modestly solves this lack.
       
      Once done this http watcher, i asked me : why not Re-build a WinHttp Request in AutoIt from a selected Request in one Click ?
      So i have added a "Create au3" button who open the WinHttp Request of your choice in AutoIt format in SciTE Editor.
      Voila voila, hope it can help ! 
      Buttons were made online with chimply.com the easy and free buttons generator !
      See Help for more infos.
      previous downloads : 253
      source and executable are available in the Download Section
      Hope you like it !
    • AndreyS
      By AndreyS
      Tell me, please, who knows why the function does not work with the specified site? _INetGetSource ("https://residence.biz.ua/")
      It is necessary to work with the protocol https. What is the problem?
    • Luigi
      By Luigi
      Greetings,
      I want use WinHttpRequest to access a OpenShift API server, it use a self signed certificate.
      Does now work...
      I never try with a self signed certificate, how do this?
      Best regards
      Global $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "https://openshift.domain:1234/api/", False) $oHttp.Option(4) = 0x0100 + 0x0200 + 0x1000 + 0x2000 $oHTTP.Option(9) = 0x0080 ;WinHttpRequestOption_SecureProtocols ;~ $oHttp.SetClientCertificate("LOCAL_MACHINE\\Personal\\certificado.crt") $oHttp.Send() $oHttp.WaitForResponse() Local $oAllHeaders = $oHttp.GetAllResponseHeaders() $oReceived = $oHttp.ResponseText $oStatusCode = $oHttp.Status $oHttp = 0 If $oStatusCode = 200 Then ConsoleWrite("$oAllHeaders--------------------" & @LF & $oAllHeaders & "$oAllHeaders--------------------" & @LF) Else ConsoleWrite("< error = " & $oReceived & @LF & $oAllHeaders & @LF) EndIf  
×