Sample code for 30+ languages & platforms
SQL Server

HTTP Response Inspection

See more HTTP Examples

Demonstrates how to inspect the HTTP response, including the status code, status text, and response headers, for Chilkat methods that don't use an HttpResponse object.

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

    -- Returns the contents of the response body.
    DECLARE @jsonText nvarchar(4000)
    EXEC sp_OAMethod @http, 'QuickGetStr', @jsonText OUT, 'https://chilkatsoft.com/helloWorld.json'

    -- Examine the response status code.

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

    -- Examine the response status text

    EXEC sp_OAGetProperty @http, 'LastStatusText', @sTmp0 OUT
    PRINT 'response status text: ' + @sTmp0

    -- Examine the full response header.

    PRINT 'response header:'
    EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT
    PRINT @sTmp0

    PRINT '----'

    -- Examine the response content-type

    EXEC sp_OAGetProperty @http, 'LastContentType', @sTmp0 OUT
    PRINT 'LastContentType = ' + @sTmp0

    -- Examine the response last-mod date

    EXEC sp_OAGetProperty @http, 'LastModDate', @sTmp0 OUT
    PRINT 'LastModDate = ' + @sTmp0

    -- Load the response header into a Chilkat MIME object to access its fields individually.
    DECLARE @mime int
    EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT

    DECLARE @success int
    EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT
    EXEC sp_OAMethod @mime, 'LoadMime', @success OUT, @sTmp0

    DECLARE @numHeaders int
    EXEC sp_OAGetProperty @mime, 'NumHeaderFields', @numHeaders OUT
    DECLARE @i int
    SELECT @i = 0

    PRINT '---- MIME Headers ----'
    WHILE @i < @numHeaders
      BEGIN

        EXEC sp_OAMethod @mime, 'GetHeaderFieldName', @sTmp0 OUT, @i
        PRINT 'name:  ' + @sTmp0

        EXEC sp_OAMethod @mime, 'GetHeaderFieldValue', @sTmp0 OUT, @i
        PRINT 'value: ' + @sTmp0
        SELECT @i = @i + 1
      END

    PRINT '----'

    -- Get a header field value by name:

    EXEC sp_OAMethod @mime, 'GetHeaderField', @sTmp0 OUT, 'ETag'
    PRINT 'ETag: ' + @sTmp0

    -- Output:

    -- response status code: 200
    -- response status text: OK
    -- response header:
    -- Content-Type: application/json
    -- Last-Modified: Sun, 20 Aug 2023 11:36:27 GMT
    -- Accept-Ranges: bytes
    -- ETag: "34c27f8e5ad3d91:0"
    -- Server: Microsoft-IIS/10.0
    -- X-Powered-By: ASP.NET
    -- Date: Sat, 30 Aug 2025 14:38:13 GMT
    -- Content-Length: 22
    -- ----
    -- LastContentType = application/json
    -- LastModDate = 2023-08-20
    -- ---- MIME Headers ----
    -- name:  Content-Type
    -- value: application/json
    -- name:  Last-Modified
    -- value: Sun, 20 Aug 2023 11:36:27 GMT
    -- name:  Accept-Ranges
    -- value: bytes
    -- name:  ETag
    -- value: "34c27f8e5ad3d91:0"
    -- name:  Server
    -- value: Microsoft-IIS/10.0
    -- name:  X-Powered-By
    -- value: ASP.NET
    -- name:  Date
    -- value: Sat, 30 Aug 2025 14:38:13 GMT
    -- name:  Content-Length
    -- value: 22
    -- ----
    -- ETag: "34c27f8e5ad3d91:0"

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @mime


END
GO