Sample code for 30+ languages & platforms
SQL Server

Example: Http.QuickGetStr method

Demonstrates the QuickGetStr method.

Chilkat SQL Server Downloads

SQL Server
-- 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 @http int
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Keep the response body if there's an error.
    EXEC sp_OASetProperty @http, 'KeepResponseBody', 1

    -- Send the HTTP GET and return the content in a string.
    DECLARE @str nvarchar(4000)
    EXEC sp_OAMethod @http, 'QuickGetStr', @str OUT, 'https://www.chilkatsoft.com/helloWorld.json'
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT
        IF @iTmp0 = 0
          BEGIN
            -- Communications error.  We did not get a response.
            EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
            PRINT @sTmp0
          END
        ELSE
          BEGIN

            EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT
            PRINT 'Response status code: ' + @iTmp0

            PRINT 'Response body error text:'
            EXEC sp_OAGetProperty @http, 'LastResponseBody', @sTmp0 OUT
            PRINT @sTmp0
          END
        EXEC @hr = sp_OADestroy @http
        RETURN
      END


    PRINT @str

    PRINT 'Success'

    EXEC @hr = sp_OADestroy @http


END
GO