(SQL Server) URL Encoding and Decoding
Demonstrates URL encoding/decoding using the HTTP convenience methods.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @s nvarchar(4000)
SELECT @s = 'Hello World! 100% sure.'
DECLARE @encoded nvarchar(4000)
EXEC sp_OAMethod @http, 'UrlEncode', @encoded OUT, @s
PRINT 'URL encoded: ' + @encoded
-- Space → %20
-- ! → %21
-- % → %25
DECLARE @decoded nvarchar(4000)
EXEC sp_OAMethod @http, 'UrlDecode', @decoded OUT, @encoded
PRINT 'URL decoded: ' + @decoded
-- Output:
-- URL encoded: Hello%20World%21%20100%25%20sure.
-- URL decoded: Hello World! 100% sure.
EXEC @hr = sp_OADestroy @http
END
GO
|