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) multipart/form-data HTTP POSTDemonstrates how to construct and send a multipart/form-data HTTP POST. For more information, see https://chilkatsoft.com/http_multipart_form_data_post.asp
-- 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) -- This example requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. -- Sends the following multipart/form-data POST: -- 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-- -- 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' DECLARE @http int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT DECLARE @resp int EXEC sp_OAMethod @http, 'SynchronousRequest', @resp OUT, 'example.com', 443, 1, @req EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @req EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @http RETURN END EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT PRINT 'HTTP response status: ' + @iTmp0 PRINT 'Received:' EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @resp EXEC @hr = sp_OADestroy @req EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @http END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.