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) TicketBAI -- Send HTTP POSTSee more TicketBAI ExamplesDemonstrates how to send a TicketBAI POST and get the response.
-- 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. DECLARE @http int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @http, 'SetSslClientCertPfx', @success OUT, 'your.pfx', 'pfx_password' IF @success = 0 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http RETURN END -- Get the XML we wish to send in the body of the request. DECLARE @sbXml int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbXml OUT EXEC sp_OAMethod @sbXml, 'LoadFile', @success OUT, 'qa_data/payload.xml', 'utf-8' IF @success = 0 BEGIN PRINT 'Failed to load XML that is to be the HTTP request body' EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @sbXml RETURN END -- Build the following JSON -- { -- "con": "LROE", -- "apa": "1.1", -- "inte": { -- "nif": "número de identificación fiscal", -- "nrs": "nombre o Razón social", -- "ap1": "primer apellido", -- "ap2": "segundo apellido" -- }, -- "drs": { -- "mode": "140", -- "ejer": "ejercicio" -- } -- } -- Use this online tool to generate code from sample JSON: -- Generate Code to Create JSON DECLARE @json int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'con', 'LROE' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'apa', '1.1' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'inte.nif', 'número de identificación fiscal' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'inte.nrs', 'nombre o Razón social' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'inte.ap1', 'primer apellido' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'inte.ap2', 'segundo apellido' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'drs.mode', '140' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'drs.ejer', 'ejercicio' -- Add required headers... EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'eus-bizkaia-n3-version', '1.0' EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'eus-bizkaia-n3-content-type', 'application/xml' EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'eus-bizkaia-n3-data', @sTmp0 DECLARE @url nvarchar(4000) SELECT @url = 'https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena' DECLARE @bGzip int SELECT @bGzip = 1 DECLARE @resp int EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'POST', @url, @sbXml, 'utf-8', 'application/octet-stream', 0, @bGzip EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 = 0 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @sbXml EXEC @hr = sp_OADestroy @json RETURN END EXEC sp_OAMethod @http, 'ClearHeaders', NULL EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT PRINT 'response status code: ' + @iTmp0 -- Examine the response (it is already decompressed) PRINT 'response body:' EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @resp EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @sbXml EXEC @hr = sp_OADestroy @json END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.