Skip to content
Andrew Lambert edited this page Mar 10, 2024 · 79 revisions

libcURL.EasyHandle

Class Declaration

 Protected Class EasyHandle
 Inherits libcURL.cURLHandle

Remarks

This class wraps the curl_easy API. The "easy" moniker is more ironic than descriptive; for most transfers you probably want to use the cURLClient class to manage the EasyHandle for you. You can implement protocol-specific subclasses of EasyHandle and still use the cURLClient class to manage them (e.g. the FTPWildCard class.)

An instance of EasyHandle is a self-contained "session". It maintains its own caches, options, connections, cookies, etc., and can operate on one URL at a time. To share SSL session data, DNS caches, connection pools, and/or HTTP cookies among several instances of EasyHandle refer to the ShareHandle class; to share connections refer to the MultiHandle class.

Basic use

Create a new instance, then use the SetOption method to define what cURL will be doing.

For example, this snippet enables automatic gzip decompression of HTTP:

Dim cURL As New libcURL.EasyHandle
If Not cURL.SetOption(libcURL.Opts.ACCEPT_ENCODING, "gzip") Then
    MsgBox("cURL error: " + Str(cURL.LastError))
End If

SetOption accepts a Variant as the option value, but only certain types may be used. Setting an option value to an unsupported type will raise a TypeMismatchException.

Once all desired options have been set the transfer is ready to begin. The EasyHandle class provides a Perform method which will perform the transfer, however this method is "hard" synchronous and is not terribly useful outside of single-threaded console applications. You will almost always want to use the MultiHandle class to perform the transfer, or use the cURLClient class which will do it for you.

During a transfer, libcURL will communicate through the EasyHandle by invoking its callback methods. These shared methods invoke their associated events on the appropriate instance of EasyHandle. Refer to the documentation on each event for further details.

The DownloadStream and/or UploadStream properties supersede the DataAvailable and/or DataNeeded events, respectively. If you define a stream you must remember to set it back to Nil (or overwrite with a new stream reference) when the stream is closed.

Example

This example synchronously downloads a URL directly into a file on the user's desktop:

  Dim c As New libcURL.EasyHandle
  Dim f As FolderItem = SpecialFolder.Desktop.Child("index.html")
  Dim bs As BinaryStream = BinaryStream.Create(f, True)
  c.DownloadStream = bs
  If Not c.Perform("http://www.example.com/index.html") Then MsgBox(libcURL.FormatError(c.LastError))
  bs.Close
  c.DownloadStream = Nil ' always set to nil when complete

Event Definitions

Methods

Properties

See also


Internal API

The following methods and properties are internal to the EasyHandle and its subclasses. You don't need to worry about these unless you're modifying or subclassing the EasyHandle class.

Methods

Shared Properties

Shared Methods

Delegate Methods

These delegate types cannot be instantiated directly. Rather, these are used to differentiate among, and enforce type safety for, anonymous delegates passed into the SetOption method. SetOption will automatically marshal delegates matching these signatures and reject all others. You aren't expected to understand this unless you're overriding the default callback methods.

Clone this wiki locally