PureBasic
PureBasic
Send a Bodyless REST Request into a StringBuilder
See more REST Examples
Demonstrates Rest.FullRequestNoBodySb, which sends a request with no body and stores the text response body in a StringBuilder.
Background. This variant of the no-body full request writes the response into a StringBuilder rather than returning it as a string, which is convenient when the response will be further processed in place.
Chilkat PureBasic Downloads
IncludeFile "CkRest.pb"
IncludeFile "CkStringBuilder.pb"
Procedure ChilkatExample()
success.i = 0
rest.i = CkRest::ckCreate()
If rest.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
bTls.i = 1
bAutoReconnect.i = 1
success = CkRest::ckConnect(rest,"example.com",443,bTls,bAutoReconnect)
If success = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
; FullRequestNoBodySb sends a request with no body and stores the text response body in a
; StringBuilder.
sbResponse.i = CkStringBuilder::ckCreate()
If sbResponse.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkRest::ckFullRequestNoBodySb(rest,"GET","/api/items/123",sbResponse)
If success = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkStringBuilder::ckDispose(sbResponse)
ProcedureReturn
EndIf
responseText.s = CkStringBuilder::ckGetAsString(sbResponse)
If CkStringBuilder::ckLastMethodSuccess(sbResponse) = 0
Debug CkStringBuilder::ckLastErrorText(sbResponse)
CkRest::ckDispose(rest)
CkStringBuilder::ckDispose(sbResponse)
ProcedureReturn
EndIf
Debug responseText
CkRest::ckDispose(rest)
CkStringBuilder::ckDispose(sbResponse)
ProcedureReturn
EndProcedure