SQL Server
SQL Server
Clear a REST Response Body Stream Destination
See more REST Examples
Demonstrates Rest.ClearResponseBodyStream, which removes a response-stream destination previously configured with SetResponseBodyStream.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background. Clearing the destination restores normal behavior, in which the full-request convenience methods return the response body rather than streaming it.
Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @rest int
EXEC @hr = sp_OACreate 'Chilkat.Rest', @rest OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @bTls int
SELECT @bTls = 1
DECLARE @bAutoReconnect int
SELECT @bAutoReconnect = 1
EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'example.com', 443, @bTls, @bAutoReconnect
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
RETURN
END
-- The file paths are relative to the application's current working directory. Absolute paths
-- may also be used. Supply the paths appropriate to your own environment.
DECLARE @respStream int
EXEC @hr = sp_OACreate 'Chilkat.Stream', @respStream OUT
EXEC sp_OASetProperty @respStream, 'SinkFile', 'qa_output/response_body.dat'
DECLARE @bAutoSetCharset int
SELECT @bAutoSetCharset = 1
DECLARE @expectedStatus int
SELECT @expectedStatus = 200
EXEC sp_OAMethod @rest, 'SetResponseBodyStream', @success OUT, @expectedStatus, @bAutoSetCharset, @respStream
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @respStream
RETURN
END
-- Clear the response-stream destination previously configured, so subsequent full-request calls
-- return the response body normally instead of streaming it.
EXEC sp_OAMethod @rest, 'ClearResponseBodyStream', NULL
PRINT 'Response body streaming cleared.'
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @respStream
END
GO