SQL Server
SQL Server
Example: Http.HttpBinary method
Demonstrates theHttpBinary method.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @localFilePath nvarchar(4000)
SELECT @localFilePath = 'C:/example/zips/data.zip'
DECLARE @bd int
EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @bd, 'LoadFile', @success OUT, @localFilePath
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @bd, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @bd
RETURN
END
EXEC sp_OAMethod @bd, 'GetData', @zipBytes OUT
DECLARE @url nvarchar(4000)
SELECT @url = 'https://example.com/api/v1/sites/123/deploys'
-- Send a POST with a binary HTTP request body.
DECLARE @resp int
EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
EXEC sp_OAMethod @http, 'HttpBinary', @success OUT, 'POST', @url, @zipBytes, 'application/zip', @resp
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @bd
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT 'Response Status Code: ' + @iTmp0
PRINT 'Response body:'
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @bd
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
END
GO