Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nBAutoReconnect
LOCAL oSbRequest
LOCAL oSbResponse
LOCAL cResponseText
nSuccess := 0
oRest := CreateObject("Chilkat.Rest")
nBTls := 1
nBAutoReconnect := 1
nSuccess := oRest:Connect("example.com", 443, nBTls, nBAutoReconnect)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
// 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.
oSbRequest := CreateObject("Chilkat.StringBuilder")
oSbRequest:Append('{ "query": "chilkat" }')
oRest:AddHeader("Content-Type", "application/json")
oSbResponse := CreateObject("Chilkat.StringBuilder")
nSuccess := oRest:FullRequestSb("POST", "/api/search", oSbRequest, oSbResponse)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
oSbRequest:destroy()
oSbResponse:destroy()
RETURN
ENDIF
cResponseText := oSbResponse:GetAsString()
IF (oSbResponse:LastMethodSuccess == 0)
? oSbResponse:LastErrorText
oRest:destroy()
oSbRequest:destroy()
oSbResponse:destroy()
RETURN
ENDIF
? cResponseText
oRest:destroy()
oSbRequest:destroy()
oSbResponse:destroy()