Skip to content

Query URL metadata example

Andrew Lambert edited this page Jan 8, 2023 · 8 revisions

Remarks

libcURL can be used to query the remote server for metadata about a resource without actually transferring the resource. A typical example would be using the HTTP HEAD request method to determine the size of the resource, but other protocols have comparable features and other kinds of metadata may be available. Metadata is also usually available after transferring a resource.

Examples

This example queries the modification time of a file on a FTP server.

  Dim curl As New cURLClient
  Call curl.SetOption(libcURL.Opts.FILETIME, True) ' request file time
  If curl.Head("ftp://ftp.example.com/directory/subdirectory/file.bin") Then ' Perform a headers-only operation
    ' Get the modification date if it was available.
    Dim modtime As Date = curl.GetInfo(libcURL.Info.FILETIME)
    If modtime <> Nil Then MsgBox("Last modified: " + modtime.SQLDateTime)
  Else
    MsgBox(libcURL.FormatError(curl.LastError))
  End If

This example queries the size of a file on a HTTP server.

  Dim curl As New cURLClient
  If curl.Head("http://www.example.com/directory/subdirectory/file.bin") Then ' Perform a headers-only operation
    ' Get the length of the download
    Dim size As Integer = curl.GetInfo(libcURL.Info.CONTENT_LENGTH_DOWNLOAD)
    MsgBox("File size: " + Str(size) + " bytes.")
  Else
    MsgBox(libcURL.FormatError(curl.LastError))
  End If

See also

Clone this wiki locally