SQL Server
SQL Server
Set a Multipart Part Body from a String
See more REST Examples
Demonstrates Rest.SetMultipartBodyString, which sets the text body of the currently selected multipart part.
Background. A multipart request is assembled part by part: the part selector chooses the part being built, header fields describe it, and a SetMultipartBody method supplies its content. The request is then sent with a multipart send or full-request 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
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
-- Select the multipart part to build, and set its header fields.
EXEC sp_OASetProperty @rest, 'PartSelector', '1'
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Disposition', 'form-data; name="field1"'
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'text/plain'
-- Set the text body of the selected multipart part.
EXEC sp_OAMethod @rest, 'SetMultipartBodyString', @success OUT, 'value1'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
RETURN
END
-- Send the multipart request using the configured part(s).
DECLARE @responseText nvarchar(4000)
EXEC sp_OAMethod @rest, 'FullRequestMultipart', @responseText OUT, 'POST', '/api/upload'
EXEC sp_OAGetProperty @rest, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
RETURN
END
PRINT @responseText
EXEC @hr = sp_OADestroy @rest
END
GO