Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Add Data to multipart/form-data RequestDemonstrates how to add content (such as a JPG, PDF, XML, etc.) to multipart/form-data requests.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- This example requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @req int -- Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OASetProperty @req, 'HttpVerb', 'POST' EXEC sp_OASetProperty @req, 'ContentType', 'multipart/form-data' EXEC sp_OASetProperty @req, 'Path', '/xyz/something' EXEC sp_OAMethod @req, 'AddParam', NULL, 'param1', 'value1' EXEC sp_OAMethod @req, 'AddParam', NULL, 'param2', 'value2' -- Add some small files to the request. (Small so we can see what the full request looks like without too much data..) DECLARE @bd int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT DECLARE @success int EXEC sp_OAMethod @bd, 'LoadFile', @success OUT, 'qa_data/jpg/starfish20.jpg' EXEC sp_OAMethod @req, 'AddBdForUpload', @success OUT, 'starfish20', 'starfish20.jpg', @bd, 'image/jpeg' EXEC sp_OAMethod @bd, 'LoadFile', @success OUT, 'qa_data/pdf/helloWorld.pdf' EXEC sp_OAMethod @req, 'AddBdForUpload', @success OUT, 'helloWorld', 'helloWorld.pdf', @bd, 'application/pdf' EXEC sp_OAMethod @bd, 'LoadFile', @success OUT, 'qa_data/xml/tinyA.xml' EXEC sp_OAMethod @req, 'AddBdForUpload', @success OUT, 'tinyA', 'tinyA.xml', @bd, 'text/xml' -- This HTTP request contains binary data, so we cannot call GenerateRequestText -- to examine it as a string. We can instead call GenerateRequestFile -- to write the request to a file and then examine using a hex editor, -- or an editor that is capable of handling null bytes and non-printable chars (perhaps by displaying "?" chars instead). EXEC sp_OAMethod @req, 'GenerateRequestFile', @success OUT, 'qa_output/multipartFormDataRequest.bin' PRINT 'OK.' -- This is the HTTP multipart/form-data request built by the above code: -- POST /xyz/something HTTP/1.1 -- Host: domain -- Content-Type: multipart/form-data; boundary=------------090708030009010000030901 -- Content-Length: 2220 -- -- --------------090708030009010000030901 -- Content-Disposition: form-data; name="param1" -- -- value1 -- --------------090708030009010000030901 -- Content-Disposition: form-data; name="param2" -- -- value2 -- --------------090708030009010000030901 -- Content-Disposition: form-data; name="starfish20"; filename="starfish20.jpg" -- Content-Type: image/jpeg -- -- JPEG DATA HERE... -- --------------090708030009010000030901 -- Content-Disposition: form-data; name="helloWorld"; filename="helloWorld.pdf" -- Content-Type: application/pdf -- -- PDF DATA HERE... -- --------------090708030009010000030901 -- Content-Disposition: form-data; name="tinyA"; filename="tinyA.xml" -- Content-Type: text/xml -- -- XML DATA HERE... -- --------------090708030009010000030901-- -- EXEC @hr = sp_OADestroy @req EXEC @hr = sp_OADestroy @bd END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.