SQL Server
SQL Server
Clear All Request Headers on a REST Object
See more REST Examples
Demonstrates Rest.ClearAllHeaders, which removes every request header previously added to the object.
Background. Clearing headers is a convenient way to reset request state before reusing the same Rest object for an unrelated request.
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
-- Connect to the REST server. The 3rd argument enables TLS (use 1 for HTTPS on port 443),
-- and the 4th enables automatic reconnection if the connection is dropped between requests.
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
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Accept', 'application/json'
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'X-Custom-Header', 'example-value'
-- Remove all request headers previously added to this object, for example before reusing the same
-- Rest object for a different request.
EXEC sp_OAMethod @rest, 'ClearAllHeaders', @success OUT
PRINT 'All request headers cleared.'
EXEC @hr = sp_OADestroy @rest
END
GO