B4X
B4X
Send a REST Request using StringBuilder Bodies
See more REST Examples
Demonstrates Rest.FullRequestSb, which sends a complete request whose text body is read from a StringBuilder and stores the text response body in a second StringBuilder.
Background. Using StringBuilder objects for the request and response bodies avoids extra string conversions, which is helpful when working with large payloads.
Chilkat B4X Downloads
Dim success As Boolean = False
Dim rest As ChilkatRest
rest.Initialize("rest")
Dim bTls As Boolean = True
Dim bAutoReconnect As Boolean = True
success = rest.Connect("example.com", 443, bTls, bAutoReconnect)
If success = False Then
Log(rest.LastErrorText)
Return
End If
' FullRequestSb sends a request whose text body is read from a StringBuilder and stores the text
' response body in a second StringBuilder. This avoids extra string conversions for large bodies.
Dim sbRequest As ChilkatStringBuilder
sbRequest.Initialize
sbRequest.Append("{ " & Chr(34) & "query" & Chr(34) & ": " & Chr(34) & "chilkat" & Chr(34) & " }")
rest.AddHeader("Content-Type", "application/json")
Dim sbResponse As ChilkatStringBuilder
sbResponse.Initialize
success = rest.FullRequestSb("POST", "/api/search", sbRequest, sbResponse)
If success = False Then
Log(rest.LastErrorText)
Return
End If
Dim responseText As String = sbResponse.GetAsString
If sbResponse.LastMethodSuccess = False Then
Log(sbResponse.LastErrorText)
Return
End If
Log(responseText)