Sample code for 30+ languages & platforms
SQL Server

Setting a HTTP Max Response Size

Demonstrates the MaxResponseSize property.

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 @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 @maxSz int
    SELECT @maxSz = 16384
    EXEC sp_OASetProperty @http, 'MaxResponseSize', @maxSz

    -- Try to get something larger, such as hamlet.xml which is 279658 bytes
    DECLARE @xmlStr nvarchar(4000)
    EXEC sp_OAMethod @http, 'QuickGetStr', @xmlStr OUT, 'https://chilkatsoft.com/hamlet.xml'
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        -- If the LastErrorText contains the string "MaxResponseSize",
        -- then the HTTP request failed because the response body would've been larger than the max allowed response size.
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        RETURN
      END


    PRINT 'OK'

    EXEC @hr = sp_OADestroy @http


END
GO