Sample code for 30+ languages & platforms
Xojo Plugin

Send a REST Request with a Binary Body

See more REST Examples

Demonstrates Rest.FullRequestBd, which sends a complete request whose binary body is read from a BinData and stores the text response body in a StringBuilder.

The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background. FullRequestBd is used when the request payload is binary, such as an image or other file, while the response is textual (for example a JSON acknowledgement).

Chilkat Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

Dim rest As New Chilkat.Rest
Dim bTls As Boolean
bTls = True
Dim bAutoReconnect As Boolean
bAutoReconnect = True
success = rest.Connect("example.com",443,bTls,bAutoReconnect)
If (success = False) Then
    System.DebugLog(rest.LastErrorText)
    Return
End If

//  The file paths are relative to the application's current working directory.  Absolute paths
//  may also be used.  Supply the paths appropriate to your own environment.

//  FullRequestBd sends a request whose binary body is read from a BinData and stores the text
//  response body in a StringBuilder.
Dim bdRequest As New Chilkat.BinData
Dim bLoaded As Boolean
bLoaded = bdRequest.LoadFile("qa_data/image.png")
If (bLoaded <> True) Then
    System.DebugLog("Failed to load the request body file.")
    Return
End If

success = rest.AddHeader("Content-Type","image/png")

Dim sbResponse As New Chilkat.StringBuilder
success = rest.FullRequestBd("PUT","/api/images/1",bdRequest,sbResponse)
If (success = False) Then
    System.DebugLog(rest.LastErrorText)
    Return
End If

Dim responseText As String
responseText = sbResponse.GetAsString()
If (sbResponse.LastMethodSuccess = False) Then
    System.DebugLog(sbResponse.LastErrorText)
    Return
End If

System.DebugLog(responseText)