-
-
Notifications
You must be signed in to change notification settings - Fork 11
Query URL metadata example
Andrew Lambert edited this page Jan 8, 2023
·
8 revisions
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.
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
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2014-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.