Jump to content



Photo

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

stdoutread libcurl curl dll html

  • Please log in to reply
2 replies to this topic

#1 Rad

Rad

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 412 posts

Posted 05 May 2012 - 05:56 AM

I'm using smartee's libcURL UDF 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 cURL UDF for Autoit 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, 05 May 2012 - 07:46 AM.








#2 smartee

smartee

    Hippies.They're everywhere.

  • Active Members
  • PipPipPipPipPipPip
  • 653 posts

Posted 05 May 2012 - 02:21 PM

Um, i don't see any attachment ;)

Here's a little demo showing how to save to a variable
AutoIt         
#include <libcURL.au3> Global $bMyData = Binary("") _urlget("<a href='http://www.example.com' class='bbc_url' title='External link' rel='nofollow external'>http://www.example.com"</a>) 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 :)

#3 Rad

Rad

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 412 posts

Posted 06 May 2012 - 01:22 AM

Weird, the upload must not have gone through.

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

Thanks!





Also tagged with one or more of these keywords: stdoutread, libcurl, curl, dll, html

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users