Jump to content
Sign in to follow this  
Rad

Get the HTML response from cURL / StdOutRead with a DLL (libcurl)

Recommended Posts

Rad

I'm using to upload a file to a server. After the upload the server returns a URL to that file. My program needs to give that URL to the user.

libcURL is working fine and the upload is successful, and the HTML response needed is output to scite's console. I need the information put into the console to be stored in a variable, though, and I can't figure it out.

I think I need to use stdout or stdread to do this. I have used these before when using a run() command but this library is using a dll (and is much cleaner than my previous version which used run commands).

How do I record the output buffer of a DLL? (or whatever stdout is called).

This attachment is what I'm testing it with, just open "playground.au3" and run it. It should spit a bunch of information to the console. The top listing of variables is all from curl_getdata(), the part with brackets and arrows is from my web server. I need the second part to be put into a variable.

PS: The cURL process ID is stored as $__hcurl_process

seangriffin's manages to accomplish this, it looks like the key is to use "DllCallbackRegister". I'm trying to plug this in to smartee's UDF but the two UDF's look like completely different languages. I don't think I will be able to figure this out on my own, but I'm going to keep trying.

EDIT: You need to move the DLL's to the same folder as playground.au3, and edit "libcURL.au3" and change the #include to quotes instead of brackets. I packed it wrong.

Edited by Rad

Share this post


Link to post
Share on other sites
smartee

Um, i don't see any attachment ;)

Here's a little demo showing how to save to a variable

#include <libcURL.au3>

Global $bMyData = Binary("")
_urlget("http://www.example.com")

ConsoleWrite(BinaryToString($bMyData))

Func _urlget($sURL)

    Local $curl_handle = _curl_easy_init()

    If ($curl_handle) Then

        Local $tCURLSTRUCT_URL = DllStructCreate("char[" & StringLen($sURL) + 1 & "]")
        DllStructSetData($tCURLSTRUCT_URL, 1, $sURL)
        _curl_easy_setopt($curl_handle, $CURLOPT_URL, DllStructGetPtr($tCURLSTRUCT_URL))

        _curl_easy_setopt($curl_handle, $CURLOPT_VERBOSE, 0)

        _curl_easy_setopt($curl_handle, $CURLOPT_FOLLOWLOCATION, 1)

        _curl_easy_setopt($curl_handle, $CURLOPT_NOPROGRESS, 1)

        Local $handle = DllCallbackRegister("_my_vwrite", "uint:cdecl", "ptr;uint;uint;ptr")
        _curl_easy_setopt($curl_handle, $CURLOPT_WRITEFUNCTION, DllCallbackGetPtr($handle))

        _curl_easy_perform($curl_handle)

        DllCallbackFree($handle)
        _curl_easy_cleanup($curl_handle)
    EndIf
EndFunc   ;==>_urlget

Func _my_vwrite($buffer, $size, $nmemb, $stream)
    Local $vData = DllStructCreate("byte[" & $size * $nmemb & "]", $buffer)
    $bMyData &= DllStructGetData($vData, 1)
    Return $size * $nmemb
EndFunc   ;==>_my_vwrite

Also you may want to take a look at the example for _curl_easy_setopt in the help-file, it shows how to save the output directly to a file.

Hope this helps :)

Share this post


Link to post
Share on other sites
Rad

Weird, the upload must not have gone through.

It doesn't matter though, that example you posted does exactly what I needed.

Thanks!

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
Sign in to follow this  

  • Similar Content

    • cdeb
      By cdeb
      I'm trying to verify which is the default scanner and if it is different from what I need to propose a choice among those available.
      All this is possible with eztw32.dll however I can not make certain functions work
      Are these:
      int TWAIN_GetDefaultSourceName(LPSTR pzName)
      string TWAIN_DefaultSourceName()
      int TWAIN_GetSourceList(void)
      source: http://www.eztwain.com/pub/eztp/EZTwain_User_Guide.pdf
      I tried this way but they do not work:
      Local $pzName
      $pzName = DllCall($pathDLL,"int","TWAIN_DefaultSourceName") ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetDefaultSourceName", "str*", $pzName) ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetDefaultSourceName","str", $pzName) ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetSourceList")
      $rc = DllCall($pathDLL,"int","TWAIN_GetSourceList", "NONE", "") ;
       
      Can anyone help me?
      Everything else works, here is the code:
       
      Local $pathDLL = @ScriptDir&"\_res\eztw32.dll" Local $rc = DllCall($pathDLL,'int','TWAIN_EasyVersion') if @error <> 0 then MsgBox(16+262144, "DllCall Error", "Error load eztw32.dll") else ConsoleWrite('--> eztw32.dll version: ' & $rc[0]/100 & @CRLF) $rc = DllCall($pathDLL,"int","TWAIN_IsAvailable") If @error > 0 Then MsgBox(16+262144, "DllCall Error", "Error call DLL - TWAIN_IsAvailable") if $rc[0] <> 0 then ConsoleWrite('--> TWAIN available: RC = ' & $rc[0]&@CRLF) ;;;;;;;;;;;;;;;;;;;;;; I NEED HERE ;manual select scanner Local $hwnd $rc = DllCall($pathDLL,"long","TWAIN_SelectImageSource",'hwnd',$hwnd) ConsoleWrite('--> TWAIN_SelectImageSource = ' & $rc[0]&@CRLF) if $rc[0] <> 0 then ConsoleWrite("--> TWAIN device selected"&@CRLF) else ConsoleWrite("--> no TWAIN device selected"&@CRLF) endif Else ConsoleWrite('--> TWAIN NOT available: RC = ' & $rc[0]&@CRLF) ; es: 0 endif endif thank you
    • Mannyfresh31
      By Mannyfresh31
      Hi Everybody I want know if there is someone kind enough to help me translate this code in to Autoit please don't blame me cause I'm a newbe 
      here is the code I need to translate also I want know if it's possible to look through a DLL  functions
       
      Declaration in Visual Basic 6: 
      Simply add the DLL import unit 'cashdll.bas' to your project, 
      or add following line to the declarations part: 
      Declare Function CASH_OPENCOM Lib "CASH.DLL" (ByVal CASH_COMPORT As Long) As Long 
       
      Declaration in Visual Basic 6: 
      Simply add the DLL import unit 'cashdll.bas' to your project, 
      or add following line to the declarations part: 
      Declare Sub CASH_CLOSECOM Lib "CASH.DLL" ()
       
       
      and here is the code I have written so far
      down below is the DLL attached also a screen shot of the  exit code of SciTE
      #include<Array.au3> $CashDLL = DllOpen("C:\Users\manue\Downloads\Casll DLL\cash.dll") if $CashDLL Then MsgBox (0,"","CashDLL Open",0) $HOPPER_OPENCOM = DllCall($CashDLL,"LONG","HOPPER_OPENCOM") if isarray ($HOPPER_OPENCOM) Then _Arraydisplay ($HOPPER_OPENCOM) Else MsgBox (0,"",@error,0) EndIf $HOPPER_CLOSECOM = DllCall($CashDLL,"NONE","HOPPER_CLOSECOM") if isarray ($HOPPER_CLOSECOM) Then _Arraydisplay ($HOPPER_CLOSECOM) Else MsgBox (0,"",@error,0) EndIf DllClose ($CashDLL)  
       

      cash.dll
    • Blueman
      By Blueman
      Hey Guys,

      I have a (i think) simple question, but i can't seem to get the answer though the help-files.
      Hope that you can help me with this issue.
      - I am opening a SSH Connection with the following function
      Func _Connect($session,$usr,$pass) $exec = @ScriptDir & "\PLINK.EXE" If Not FileExists($exec) Then _Err("PLINK.EXE Not Found!",0) $pid = Run($exec & " -load " & $session & " -l " & $usr & " -pw " & $pass, @ScriptDir, @SW_HIDE, 0x1 + 0x8) ;Run SSH.EXE If Not $pid Then _Err("Failed to connect",0) $currentpid = $pid ;$rtn = _Read($pid) ;Check for Login Success - Prompt ;MsgBox(48,"","1") ;sleep(5000) ;Wait for connection Return $pid EndFunc - This will connect to a CMS Server with a vt100 interface where a dynamic report is generated every 20 seconds.
      - Then i will read the contents with the following Function
      Func _Read($pid) $SSHREADTIMEOUT = 0 If Not $pid Then Return -1 Local $dataA Local $dataB Do $SSHREADTIMEOUT += 1 $dataB = $dataA sleep(100) $dataA &= StdOutRead($pid) If @error Then ExitLoop Until ($dataB = $dataA And $dataA And $dataB) OR $SSHREADTIMEOUT == 50 Return $dataA EndFunc This all goes correctly, but i can only read the contents once.
      When i try to read the contents again i get nothing.
      Maybe because the CMS isn't changing, but the values in the report is changing every 20 seconds.
      I need to somehow read al of the contents every time i perform a Read action, but how?
      Yes, i can use it in a While loop, but also then i get nothing or a small line of text and not the whole report.
       
      Any Idea?
       
      Thanks Guys!
       
      --Edit--
      I have fixed the problem by changing the terminal session to a vt220 session.
      The only problem now is that i want to send the: "Data link escape" command and that is something i cannot fix,.
      I have tried;
      StdinWrite($Pid,Hex(0x10)) StdinWrite($Pid,Chr(16)) StdinWrite($Pid,{DLE}) But nothing seems to work.  
      -- Edit-2 --
      Guys, fixed that too!
      Forgot to add the number '5' to actually execute the assignment.
      So fixed it by using;
       
      StdinWrite($Pid,Chr(16)) StdinWrite($Pid,"5")
      Thanks for reading with me
       
    • ur
      By ur
      Is there any UDF to remove all anchor tags <a> with a particular class (and also its sub elements completely) in a html document.
      Here the classes are browse and breadcrumbs
      Like in the below image.


       
      I am not able to find that option in IE.au3
       
      Please suggest.
    • milkmoron
      By milkmoron
      I am trying to automate something in a web browser but i need some help with finding the html code to a web applet. How do I access the code.
×