SQL Server
SQL Server
Example: Http.HttpFile method
Shows how to use the HttpFile method to send an HTTP POST request with the contents of a file as the request body. The example sends the following request:POST /api/v1/sites/123/deploys HTTP/1.1 Host: example.com Accept: */* Accept-Encoding: gzip Content-Type: application/zip Content-Length: 123456 [binary data bytes of data.zip]
Also see: Chilkat Http Default and Auto-Filled Headers
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 @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @localFilePath nvarchar(4000)
SELECT @localFilePath = 'C:/example/zips/data.zip'
DECLARE @url nvarchar(4000)
SELECT @url = 'https://example.com/api/v1/sites/123/deploys'
-- Send a POST with the contents of the file in the binary HTTP request body.
DECLARE @resp int
EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT
EXEC sp_OAMethod @http, 'HttpFile', @success OUT, 'POST', @url, @localFilePath, 'application/zip', @resp
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
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 @http
EXEC @hr = sp_OADestroy @resp
END
GO