Xbase++
Xbase++
Explaining the Rest ClearResponseBodyStream Method
See more Azure Cloud Storage Examples
The ClearResponseBodyStream method would be needed if your applicaiton called SetResponseBodyStream to send the response to a stream for one request, but then wants to subsequently do something else. The application must call ClearResponseBodyStream to no longer send responses to the stream.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nPort
LOCAL nBAutoReconnect
LOCAL oFileStream
LOCAL nExpectedStatus
LOCAL cResponseStr
LOCAL oBd
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oRest := CreateObject("Chilkat.Rest")
// Connect to the web server
nBTls := 1
nPort := 443
nBAutoReconnect := 1
nSuccess := oRest:Connect("www.chilkatsoft.com", nPort, nBTls, nBAutoReconnect)
IF (nSuccess != 1)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
// Setup a file stream for the download
oFileStream := CreateObject("Chilkat.Stream")
oFileStream:SinkFile := "qa_output/starfish.jpg"
// Indicate that the call to FullRequestNoBody should send the response body
// to fileStream if the response status code is 200.
// If a non-success response status code is received, then nothing
// is streamed to the output file and the error response is returned by FullRequestNoBody.
nExpectedStatus := 200
oRest:SetResponseBodyStream(nExpectedStatus, 1, oFileStream)
cResponseStr := oRest:FullRequestNoBody("GET", "/images/starfish.jpg")
IF (oRest:LastMethodSuccess == 0)
// Examine the request/response to see what happened.
? "response status code = " + Str(oRest:ResponseStatusCode)
? "response status text = " + oRest:ResponseStatusText
? "response header: " + oRest:ResponseHeader
? "response body (if any): " + cResponseStr
? "---"
? "LastRequestStartLine: " + oRest:LastRequestStartLine
? "LastRequestHeader: " + oRest:LastRequestHeader
oRest:destroy()
oFileStream:destroy()
RETURN
ENDIF
? "downloaded starfish.jpg"
// Clear the response body stream previously set in the call to SetResponseBodyStream.
oRest:ClearResponseBodyStream()
// Download something else, but this time send the response body to bd.
oBd := CreateObject("Chilkat.BinData")
nSuccess := oRest:FullRequestNoBodyBd("GET", "/images/penguins.jpg", oBd)
IF (nSuccess == 0)
// Examine the request/response to see what happened.
? "response status code = " + Str(oRest:ResponseStatusCode)
? "response status text = " + oRest:ResponseStatusText
? "response header: " + oRest:ResponseHeader
? "response body (if any): " + oBd:GetString("utf-8")
? "---"
? "LastRequestStartLine: " + oRest:LastRequestStartLine
? "LastRequestHeader: " + oRest:LastRequestHeader
oRest:destroy()
oFileStream:destroy()
oBd:destroy()
RETURN
ENDIF
// Save the contents of bd to a file.
nSuccess := oBd:WriteFile("qa_output/penguins.jpg")
? "Success: " + Str(nSuccess)
oRest:destroy()
oFileStream:destroy()
oBd:destroy()