-
-
Notifications
You must be signed in to change notification settings - Fork 11
HTTP GET Example
HTTP/1.1 GET semantics are the default for all requests made through libcURL. Consequently, HTTP/1.1 GET requests are the simplest kinds of transfer that can be done using libcURL.
This example performs a synchronous HTTP GET request on the calling thread.
Dim curl As New cURLClient
If curl.Get("http://www.example.com/") Then
Dim page As String = curl.GetDownloadedData()
Else
MsgBox(libcURL.FormatError(curl.LastError))
End If
This example performs a synchronous HTTP GET request on the calling thread, and writes downloaded data directly to a file on the user's desktop:
Dim curl As New cURLClient
Dim output As FolderItem = SpecialFolder.Desktop.Child("file.txt")
Dim download As BinaryStream = BinaryStream.Create(output)
If Not curl.Get("http://www.example.com/file.txt", download) Then
MsgBox(libcURL.FormatError(curl.LastError))
End If
download.Close()
This example performs an asynchronous HTTP GET in a console application, and prints the output directly to stdout
. Because this is a console application an event loop must be supplied for the asynchronous transfers to run on:
Dim curl As New cURLClient
curl.Get("http://www.example.com/", stdout) ' stdout implements Writeable
Do
App.DoEvents() ' async transfers require an event loop!
Loop Until curl.IsTransferComplete
If curl.GetStatusCode <> 200 Then
Print("HTTP Status: " + Str(curl.GetStatusCode))
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.