« MBS Xojo Developer Co… | Home | xDev Magazine Issue 1… »

Starting with CURL functions

If you like to use our CURL plugin in Xojo or Real Studio, you can start with one of the example projects or from scratch. Here we show you how to make an easy download. So first you need a new object of the CURLSMBS class and you create it with the new command. Now you can set all the options like OptionURL. For the data you receive, you can subclass and implement the Write event. Or you simply set CollectOutputData to true. In that case the plugin collects the data and you later find it int he OutputData property.
To run the transfer, you call Perform method. If you run the transfer in a thread, you may want to look in the PerformMT function for better threading.
After the transfer completed and you have no error on the transfer, you can work on the result. For example you can use GetInfoHTTPConnectCode function to see what HTTP error code you got. There success has the value 200. So here is your example code:

dim c as new CURLSMBS
c.OptionURL = "http://www.monkeybreadsoftware.de/realbasic/images/MBSsmall.jpg"
c.CollectOutputData = true

dim e as integer = c.Perform
if e = 0 then
dim data as string = c.OutputData
dim pic as Picture = JPEGStringToPictureMBS(data)
Backdrop = pic
else
MsgBox "Error: "+str(e)
end if

For help on debugging what's going on, you can set OptionVerbose to true to see debug messages. if you set CollectDebugData to true, you can find the debug messages in DebugData property:

c.OptionVerbose = True
c.CollectDebugData = true
dim d as string = c.DebugData

Next you may need to add more options like OptionUserName/OptionPassword. Also you can set proxy or other authentications.
CURL is powerful and can do http requests, ftp/sftp/ftps up and downloads, send emails or send forms.
05 07 13 - 13:52