Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnBAutoReconnect
LOCAL loSbRequest
LOCAL loSbResponse
LOCAL lcResponseText

lnSuccess = 0

loRest = CreateObject('Chilkat.Rest')
lnBTls = 1
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("example.com",443,lnBTls,lnBAutoReconnect)
IF (lnSuccess = 0) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
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.
loSbRequest = CreateObject('Chilkat.StringBuilder')
loSbRequest.Append('{ "query": "chilkat" }')

loRest.AddHeader("Content-Type","application/json")

loSbResponse = CreateObject('Chilkat.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/api/search",loSbRequest,loSbResponse)
IF (lnSuccess = 0) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loSbRequest
    RELEASE loSbResponse
    CANCEL
ENDIF

lcResponseText = loSbResponse.GetAsString()
IF (loSbResponse.LastMethodSuccess = 0) THEN
    ? loSbResponse.LastErrorText
    RELEASE loRest
    RELEASE loSbRequest
    RELEASE loSbResponse
    CANCEL
ENDIF

? lcResponseText

RELEASE loRest
RELEASE loSbRequest
RELEASE loSbResponse