![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Transition from Http.PostUrlEncoded to Http.HttpReqProvides instructions for replacing deprecated PostUrlEncoded method calls with HttpReq. Sends the following raw HTTP request: POST /echoPost.asp HTTP/1.1 Host: www.chilkatsoft.com Content-Type: application/x-www-form-urlencoded Content-Length: 50 company=example&ip=111.111.111.111&url=example.com Note: This example requires Chilkat v11.0.0 or greater.
-- 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 @url nvarchar(4000) SELECT @url = 'https://www.chilkatsoft.com/echoPost.asp' DECLARE @req int EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT EXEC sp_OAMethod @req, 'AddParam', NULL, 'company', 'example' EXEC sp_OAMethod @req, 'AddParam', NULL, 'ip', '111.111.111.111' EXEC sp_OAMethod @req, 'AddParam', NULL, 'url', 'example.com' -- ------------------------------------------------------------------------ -- The PostUrlEncoded method is deprecated: DECLARE @responseObj int EXEC sp_OAMethod @http, 'PostUrlEncoded', @responseObj OUT, @url, @req 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 @req RETURN END -- ... -- ... EXEC @hr = sp_OADestroy @responseObj -- ------------------------------------------------------------------------ -- Do the equivalent using HttpReq. -- Your application creates a new, empty HttpResponse object which is passed -- in the last argument and filled upon success. DECLARE @req2 int EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req2 OUT EXEC sp_OAMethod @req2, 'AddParam', NULL, 'company', 'example' EXEC sp_OAMethod @req2, 'AddParam', NULL, 'ip', '111.111.111.111' EXEC sp_OAMethod @req2, 'AddParam', NULL, 'url', 'example.com' EXEC sp_OASetProperty @req2, 'HttpVerb', 'POST' EXEC sp_OASetProperty @req2, 'ContentType', 'application/x-www-form-urlencoded' DECLARE @resp int EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT EXEC sp_OAMethod @http, 'HttpReq', @success OUT, @url, @req2, @resp IF @success = 0 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @req EXEC @hr = sp_OADestroy @req2 EXEC @hr = sp_OADestroy @resp RETURN END -- Results are contained in the HTTP response object... EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @req EXEC @hr = sp_OADestroy @req2 EXEC @hr = sp_OADestroy @resp END GO |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.