SQL Server
SQL Server
Transition from Http.PostUrlEncoded to Http.HttpReq
Provides 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
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
-- 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